4 smart ways to write Python program

Betaspyder
2 min readJul 25, 2022

--

4 smart ways of writing 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

Split function

#Tip 3

The following program is to find the given number is odd or even.

Normal way of writing odd or even

The same can be done in smarter way.

smart way of writing

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

  1. Create an empty list
  2. Generate numbers from 1 to 10 using for loop.
  3. 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.

--

--

Betaspyder

Technical Writer, Content Creator, Content Writer, Python, Data Analyst, Database, HTML, Javascript