Check Point 3.3
1. What is an expression in Python?
Answer: A valid combination of literals, variables and operators are called Expression. An expression represents something, which Python evaluates and which then produces a value.
2. What is a statement in Python? How is a statement different from expression?
Answer: Statement is a programming instruction that does something i.e. some action takes place. It is not necessary that a statement result a value.
Expression is evaluated and result a value, while statement executed and does not result a value.
For example:
Statement :
print(a)
if a > 5:
Expression :
a = b + 3
3. What is comment? In how many ways can you create comments in Python?
Answer: Comment is a non-executable statement, which is read by programmers but ignored by the Python Interpreter.
In Python, comments can be written by using # (hash or pound character) and triple quote (either single or double)
(a) Full line comment and Inline comment : This type of comment is start with # (pound / hash ) symbol.
Full Line Comment: The physical lines beginning with #.
#Hello my dear students
#Welcome, Anjeev Singh Academy
#Want this solution in pdf , contact me.
Inline Comment: It starts with # in the middle of physical line.
p = 2569.66 # p is a principal amount, inline comment
(b) Multi-line Comment: Multi-line comment is also known as block comment. It can be in two ways –
Using # Symbol – in the beginning of each physical line.
#Hello my dear students
#Welcome, Anjeev Singh Academy
#Want this solution in pdf , contact me.
Using triple quote – multi-line strings are enclosed with triple quote (either single or double triple quote).
‘‘‘
Hello my dear students
Welcome, Anjeev Singh Academy
Want this solution in pdf , contact me.
’’’
“ “ “
Hello my dear students
Welcome, Anjeev Singh Academy
Want this solution in pdf , contact me.
” ” ”
4. How would you create multi-line comment in Python?
Answer: Multi-line comment is also known as block comment. It can be in two ways –
(a) Using # Symbol – in the beginning of each physical line.
#Hello my dear students
#Welcome, Anjeev Singh Academy
#Want this solution in pdf , contact me.
(b) Using triple quote – multi-line strings are enclosed with triple quote (either single or double triple quote).
‘‘‘
Hello my dear students
Welcome, Anjeev Singh Academy
Want this solution in pdf , contact me.
’’’
“ “ “
Hello my dear students
Welcome, Anjeev Singh Academy
Want this solution in pdf , contact me.
” ” ”
5. What is the difference between full-line comment and inline comment?
Answer: Differences between full-line comment and inline comment are :-
(i) In Full line comment, the physical lines begin with # symbol, while in Inline comment, # symbol comes in the middle of physical line.
(ii) Full line comment is used for describing the purpose of program, date of program, author of program, etc, While Inline comment is used for describing the purpose of Python Instructions / Statements / Variable, etc.
6. What is a block or suite in Python? How indentation related to it?
Answer: A group of statements which are part of another statement of a function are called block or suite or code-block in Python.
Python uses indentation to create blocks of code. Statements at same indentation level are part of same block / suite.
Note: Statements requiring suite / code-block have a colon : at their end. You cannot unnecessarily indent a statement; Python will raise error for that.