Page 245 - AI Computer 10
P. 245
Comments
Comments refer to the statements that are added to a program with the purpose of making the code easier
to understand. These statements are ignored by compilers and interpreters. There are two types of comments
in Python.
u Single line comment u Multi-line comment
Single-Line Comment
In Python, the symbol # is used to start a comment. Whatever is written after this symbol will be not be printed
on the screen.
# This is just a comment. Anything written here is ignored by Python compiler.
Example:
Multi-line Comment
To have a multi-line comment in Python, we use triple single quotes at the beginning and at the end of the
comment. The sytax for writing multi line comment is:
‘‘‘This is a
multi-line
3-line comment’’’
Example:
Keywords
Keywords are the reserved words in programming language that convey a special meaning to the language
compiler/interpreter. These words must not be used as normal variable names. Some reserved words for Python
programming language are as follows:
none false elif else
true as continue return
and global break try
finally def import or
Variables
Variables act as a container for storing values. A memory location which is used to store data created in the main
memory of a computer is called a variable. These locations are created and identified by the given name while
executing a program. Using variables, values are stored and manipulated to produce the desired results.
Rules for Naming Variables
The naming convention plays an important role while creating variables. You should follow certain rules for
naming a variable in Python. These rules are as follows:
111
111