Python Basic and Syntax Exercises

 >>>print 'Hello, World!'


print 'Hello, World!'
^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
#This will print in the terminal: Hello, World! in Python 2. When using Python 3 we use parentheses. print ('Hello, World!')

>>> 1/2
0.5
#This is the operator / which performs a division.



>>>type(1/2)
<class 'float'>
#This will show since the result of 1/2 is 0.5 and that is a floating-point number.
#In this result, the word “class” is used in the sense of a category; a type is a category of values.

>>>print(01)
print(01)
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
#This will throw an error. There are syntax rules in Formal Languages and leading zeros in decimal integer literals are not permitted.

>>>1/(2/3)
1.5
//This will print 1.5. Why? Becuase parantheses have the highest precedence when it comes to operations. So we divide what's inside the parantheses. then we divide 1 with the result.
Stephen Olubanji Akinpelu

Previous Post Next Post