Unit 1 : PYTHON Revision Tour - 1
➢ Program: Sequence of instructions given to the computer to perform a particular task.
➢ IDE: IDE stands for Integrated Development Environment. Every programming has its
own IDE, which provides the facility to write/test/run/debug code.
➢ IDLE: IDLE Stands for Integrated Development & Learning Environment. It is Python's
official IDE.
➢ Tokens/Lexical Unit: The smallest Individual elements of a programming language are
known as Token/Lexical Unit. Tokens are divided into five parts: keyword, identifier,
literal/punctuator, separator & operator.
➢ Keyword: Keywords are reserved words by a programming language. Python has a
total of 35 keywords.
➢ Identifier: Identifiers are the names given to a variable, function, class, etc.
➢ Literal/Constant: Literal/Constants are fixed values whose value cannot be changed
during the execution of the program.
➢ Punctuator/Separator: Punctuators or separators separate one token from another.
➢ Operator: Operators are used to perform some operations. There are different types
of operators in Python programming: Arithmetic Operator, Relational Operator, Logical
Operator, Assignment Operator, Membership Operator etc.
➢ Variable: The variable is named memory locations, which can store some value and
whose value can be changed as and when required.
➢ Dynamic Typing: In Python Programming, you declare a variable and put some values
into it. The variable's type is automatically defined based on the stored value. It is
called Dynamic Typing.
➢ Type Casting/Conversion: Conversion of one data type into another is called Type
Conversion.
➢ Type Conversion has two types: i) implicit type conversion and ii) explicit type
conversion.
➢ Implicit Type Conversion: The type conversion done internally by Python is called
"Implicit Type Conversion".
➢ Explicit Type Conversion: The type conversion done by the user as and when required
is called Explicit Type Conversion. It is also known as Type Casting.
➢ int()/float()/str() etc. are used for type conversion. In type conversion, the int()
function is used to convert the value to integer format, float() is used to convert the
value to decimal format, and the str() function is used to convert the value to string
format.
➢ Control Statement: Control Statement is used to control the flow of execution of a
programming language. h is broadly divided into three parts: Selection control
statement, Jump control statement, and looping/Iterative control statement.
➢ Selection Control Statement: It selects which statement will be executed based on a
condition. "if" is a selection control statement.
1|Page
➢ Jump Control Statement: It is used to redirect the flow of control of a programming
language. The Jump Control statements are break, continue & pass.
➢ Loop/lterative Control Statement: Loop/Iterative control statement executes a single
statement or a block of statements n times until the condition is True.
➢ The Break statement is used to break the execution of a loop.
➢ The continue statement is used to restart the loop from the point where it is
encountered.
➢ print() function is used to print something on the output console. By default, the
print() function prints everything in a new line.
➢ input() function is used to take input from the user. Note that the input() function
inputs everything in the str) (string) format.
Fill in the blanks:
a. IDLE Stands for Integrated Development and Learning Environment
b. IDE stands for Integrated Development Environment
c. The latest version of IDLE is 3.12.1 [refer [Link] for updated version]
d. Control statements in Python are broadly divided into three (03) parts.
e. To select the statement for execution based on a condition we use Selection control
statement.
f. Python is an interpreted, high-level programming language known for its readability and
concise syntax.
g. Python is a Dynamically Typed Language.
h. The process of combining two or more strings in Python is called string concatenation.
i. To control the flow of control we use Control Statements.
j. The conditional statement used to execute a block of code only if a certain condition is true
is called an if statement.
k. To execute a statement "n" times till the condition is True we use Loop/Iterative Control
Statement.
l. The statement that breaks the execution of a loop is break Statement.
m. To restart the loop at a point of time we use continue Statement.
n. The pass statement is null statement in Python.
o. The smallest individual elements of a programming language are called Lexical Unit/TOKEN.
2|Page
Q1. What is Static and Dynamic Typing? Explain with Example.
Ans: Static Typing - In this type of typing concept, we first must declare the variable with its
data type and store values. A variable declared with a specified data type could store only the
same data type. This concept was used in earlier programming languages like C/C++/Java, etc.
For example:
int a;
a=10
Dynamic Typing - In this type of typing concept, we declare the variable and store values.
Depending upon the values stored in the variable, the data type is automatically decided. For
example: A=10
Here variable "A" automatically becomes an integer type as the value stored in A is an integer.
Python supports "Dynamic Typing".
Q2. Define loop with its different types along with an example.
Ans: Loops are used to execute a single statement or a block of statement "n" times till the
condition is True. Python supports two types of looping statements, i.e., while & for loop.
"while" and "for" loop both are used for looping statement.
Syntax of While Loop
initialization
while condition:
statement(s)
-----------------
Increment/decrement
Syntax of for loop
for variable in range(start_value, end_value, step_value):
statement(s)
------------------------
Q3. What is the purpose of an if-else statement in Python?
Ans: An if-else statement in Python is to make decisions based on a given condition. The If
statement checks a condition and executes the statement based on the condition. If the
condition is True, it executes some statements; if the condition is False, it executes another
set of statements.
3|Page
Q4. How does a while loop differ from for loop in Python?
Ans: A while loop contains a condition, and it executes until the given condition is True. The
loop gets terminated when the condition becomes False.
Syntax: initialization
while condition:
Statement 01
Statement 02
------------------------
Statement n
In the case of for loop, the range() function generates a range of values, and the loop will run
for all those values.
Syntax: for variable in range(value):
Statement(s)
Q5. Explain the role of the elif statement in an if-else construct.
Ans: The elif statement introduces an additional condition in an if-else construct. It allows for
checking multiple conditions in sequence, and if the previous conditions are false, it tests the
current condition. In simple words, it moves to the next elif condition when the current
condition is False. If the current condition is True, it executes the current block and terminates
the if-else construct.
Q6. How can you create a loop that iterates from 1 to 10 in Python?
Ans: To create a loop that iterates from 1 to 10, we can use "for loop" with the range() function:
for i in range(1, 11):
print(i)
Q7. What does the break keyword do in a loop? Provide an example.
Ans: The break keyword is used to exit a loop prematurely. For example consider the following
code fragment:
for i in range(1, 6):
if i==3:
break
print(i)
The loop as above is meant to run from 1 to 5. But when the value of "i" reaches 3, the break
statement will be encountered, and the loop will be terminated.
4|Page
Q8. Describe the purpose of the range() function in Python loops.
Ans: The range() function generates a sequence of numbers, often used as an iterator in loops.
It can take parameters for start, stop, and step values to customize the range.
Q9. How can you use nested loops to create a pattern of stars in Python?
Ans: When there is one loop inside another loop, it is called Nested Loop. Nested loops are
usually used to create patterns of stars or other elements. For example, a nested loop to print
a triangle of stars:
for i in range(5):
for j in range(i + 1):
print("*", end="")
print()
Q10. What is the difference between pre-increment and post-increment operators in
Python?
Ans: There is no pre- or post-increment operator in Python like in C/C++/Java and other
languages. In Python, there exists only an increment concept which increments the value of a
variable by a specific value.
Q11. Explain the concept of "control flow" in Python programming.
Ans: "Control flow" refers to the sequence in which statements are executed in a program. We
can control the flow of execution by conditional statements, loops, and branching constructs
like if-else, while, and for loops.
5|Page