4 smart ways to write Python program
#Tip 1
Do you want to print “Hello World” without using print statement?
then, just import __hello__
#Tip2
Do you want to give multiple inputs in single line?
just use split() function
#Tip 3
The following program is to find the given number is odd or even.
The same can be done in smarter way.
if the condition is true then it has to print even no otherwise it will print odd as the output
#Tip4
Consider, Our aim is to create a list that should have square numbers between 1 and 10. look at the steps
- Create an empty list
- Generate numbers from 1 to 10 using for loop.
- write the condition for generating squares.
4. Add the square numbers in the list using append.
5. Print the result
The following image will help you to get the logic
The above has taken 5 lines of code to print the result. The same output can be obtained just by writing 2 lines.
If you found this article useful, please share this with your friends and give a clap here. Stay tuned. Follow me on GitHub and Twitter.