Python Syntax:
(1.)Python syntax can be executed by writing directly in the command line. Ex
>>>print(“Hello “)
Hello
Or by creating a python file (Note pad)on the server, using the .py file extension, and running it in the Command Line:
open a note pad: type the following syntax:
print("Hello")
save as ex.py
open commandline, go to the directory(folder) where you saved ex.py file, type python ex.py
C:\Users\Rajendra>python ex.py
(2.) Python Indentation
Where in other programming languages the indentation in code is for readability only, in Python the indentation is very important.
Python uses indentation to indicate a block of code.
if 10 > 2:
print("Ten is greater than two!")
print("Ten is greater than two!")
The above is giving indentation otherwise leads to error
For example:
if 10 > 2:
print("Ten is greater than two!") # this is error bcoz there is no indentation
What is Indentation?
Python uses a different methodology. Python programs get structured through indentation, i.e. code blocks are defined by their indentation.
All statements with the same distance to the right belong to the same block of code, i.e. the statements within a block line up vertically. The block ends at a line less indented or the end of the file. If a block has to be more deeply nested, it is simply indented further to the right.
No comments:
Post a Comment