Saturday, 17 June 2017

How to use Syntax Differences between Python 2 and Python 3 | Softcrayons IT Training Tutorial

For beginners, there are few points to remember if you have thought of learning Python. We will Discuss 2 of them here:


  1. Printing values on screen
  2. User input
There are many more small differences that I won’t get into for now.





  1. Printing values
The first most basic difference you will notice b/w python 2 and python 3 versions is printing values on the screen.





Python 2 Python 3
print“Hello” print(“Hello”)



In python 2, to print a value you just need to apply quotes after
print syntax because print behaves as an operator, which means it
operates on whatever comes after it. In python 3, print is a function
that takes arguments, So parenthesis are must.


So remember whenever you see error like this


>>>print“Lucious”File”<stdin>”,line1print“Lucious”^SyntaxError:Missingparenthesesincallto’print’  It means you were trying use python 2 syntax in python 3. 2.    User Input Next
difference you should know is about user input used to take values from
user. In python 2 the raw_input()function was used but in python 3 it
is removed and is replaced by input()


It means for both strings and integers you will use this functions only if working in python 3.



How to use Syntax Differences between Python 2 and Python 3 | Softcrayons IT Training Tutorial

No comments:

Post a Comment