Comments
Comment is used to mark non executed part of python programming code which is usually use for the purpose of in-code documentation. Python offers two ways of defining text as a comment and not as code. The first method is the single-line comment. It uses the number sign (#)
Example
# This is a comment.
print(" I am python programming Instructor ") #This
is also a comment.
A single-line
comment can come out on a line by
itself or it can come out after executable code. A single-line comment can be used
for short descriptive text, such as an explanation of a particular
bit of code.
A multiline
comment is used to create a longer comment, it starts and ends with three
double quotes (""")
,
Example
"""
Payroll
and accounting application
Botany
Company Limited
Designed
by : John smith
Purpose: Shows how to use comments.
"""
Creating Variables
Python has no command for declaring a variable just like other programming languages
A variable is created the by assign a value to it.
Variable Names
A variable name can be short (like a and b) or a more descriptive name (age, studname, addres).
Rules in formulating variable name in Python:
• It must start with a letter or the underscore character
• It cannot start with a number
• It can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
• It is case-sensitive (Nam, nam and NaM are three different variables)
Example
a = 520
nam = "Peter John"
print(x)
print(y)
Variables do not need to be declared with any particular type and can even change type after they have been set.
Example
n= 25 # n is of type int
xn= "Sally" # n is now of type str
print(x)