Python Programming
About Lesson

Block or Compound Statement is now ‘Suite’

There are no curly braces({ }) usage in python like in C, C++ and java.  The opening and closing curly braces are used to group a logically connected group of statements in those languages.  The group of statements enclosed between two curly braces are known as block, code block or compound statement which are specifying the body of a loop statement or a function.

Python calls the code block as a suite that can be understood by a colon (:) which indicating the beginning of a suite.  After that we have to use indentation to specify all the statements of the suit.  The indentation is a space maintained from left hand side.  The code lines with same amount of indent would be treated as a single block.

Example:

if (a>b) :

               print “a is big”   #indentation from left hand side

else :

               print “b is big”

 

Splitting a code line

It is possible to enter a single code line into multiple lines but adding \ at the end of the line.  The popular termination character of C/C++/java that is semicolon (;) is not mandatory in python.  But semicolon must be presented when you want to enter more than one executable statement in a  single line.

 

Example:

print (“The statement that \

can be entered in \

multiple lines”)

print (“I am”); print(“looking”); print (“as single statement”)

 

String literals

Python accepts single (‘), double (“) and triple (”’ or “””) quotes to denote string literals, as long as the same type of quote starts and ends the string.  The triple quotes also allow you to span the string across multiple lines.

 

Example:

FirstName=’Abc’

LastName=”Def”

Address=”””D.No.123,Unknown Street, Unknown City,

Planet Earth”””

print (FirstName,LastName)

print (Address)

 

Comments

Comments are useful for the developer to provide description for the coding so that it can be easily understood in future.  Comments are only useful or visible for the developer only.  In Python, there are two types of comment styles.

#(hash) for single line comment line style

‘’’(triple single quotes) or “”” (triple double quotes) for multi-line comment line style

You cannot copy content of this page