This is the first tutorial of Python which will include examples and help the learner to understand easily.
Example 1:
print("Hello, World!")
Solution: Hello, World!
Python Indentations
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.
Example 2:
if 7 > 2:
print("Seven is greater than two!")
print("Seven is greater than two!")
Solution: Seven is greater than two!
Note: In the above example we have given indentation after colon(:) which indicate that the print statement come under the if block.
Python Variables
In Python variables are created to assign memory to a value:
Example 3:
x = 5
y = "Hello, World!"
In above example x and y are variable to which 5 and hello world is assigned.
Comments in Python
Python has commenting capability for the purpose of code documentation.
Comments start with a #, and Python will treat the rest of the line as a comment:
Example 4:
#This is a comment.
print("Start Python")
Comments do not execute it is ignored by python.
Multi Line Comments
Python does not really have a syntax for multi line comments.
To add a multi-line comment you could insert a
#
for each line:
Or, not quite as intended, use a multi-line string.
Example 5:
"""
This is a comment
written in
more than just one line
written in
more than just one line
"""
This will create a multi-line comment for you.
0 Comments