Python 3-Basic Syntax

Python Syntax

The Python syntax is as simple for the programmers. Like C and Java, we don't have complex guidelines for Python syntax. Instead of of set brackets, we follow intendations for local blocks.

>>> x=1
>>> if x==1:
...     print ("Hello")
...
Hello
>>>

In the above example, "if" condition is given with proper indentation, otherwise it shows indent error.

Python as a Calculator

Python interpreter acts as a simple calculator, you can give the expression and it will write the value. The expression syntax is straightforward: the operators +, - , * and / work just like most other languages and the parentheses () can be used for grouping.

>>> 8+1
9
>>> 40-4*5
20
>>> (40-4*5)/4
5.0
>>> 6/5
1.2
>>>

In the above, example you could see the division always returns float variable and to get the remainder we can use % operator