-----------------------------------------------------------------------------------------------------------------------------
Indentation
-----------------------------------------------------------------------------------------------------------------------------In c -------->> if n>0
{
print { "postive number"}
}
In Python --------->> if n>0:
print ("postive number")
else:
print ("negative number")
Note:
Once we given (:), next line will take automatically 4 spaces.
It means below lines belongs to IF condition.
-----------------------------------------------------------------------------------------------------------------------------
Once we given (:), next line will take automatically 4 spaces.
It means below lines belongs to IF condition.
-----------------------------------------------------------------------------------------------------------------------------
Comments
-----------------------------------------------------------------------------------------------------------------------------Single Line ----->>(#)
# this code is to show an example of a single-line comment
print( 'This statement does not have a hashtag before it' )
O/p: print( 'This statement does not have a hashtag before it' )
Multiline----->>(''') or (""")
Multiline----->>(''') or (""")
# Code to show how we use docstrings in Python
def add(x, y):
"""This function adds the values of x and y"""
return x + y
Example:
"""This function adds the values of x and y"""
return x + y
Example:
#Python Program
#Single-Line Comment - tarts with the hash # character followed by text for further explanation.
#Example
#Single-Line Comment - tarts with the hash # character followed by text for further explanation.
#Example
name = "Thomas" # Assigning string value to the name variable
Fees = 10000 # defining course fees is 10000
Marks = 90 # defining the marks of a student
print (name,Fees,Marks )
print ("===============================")
#Multi-Line Comments - Python does not have explicit support for multi-line comments but we can use hash # character to the multiple lines.
# Code to show how we use docstrings in Python
def add(x, y):
"""This function adds the values of x and y"""
return x + y
# Displaying the docstring of the add function
print( add.__doc__ )
Note: Save with .py Extenstion, then run the file in IDLE shell
Output:
Thomas 10000 90
===============================
This function adds the values of x and y