1. What is used to represent Strings in Python?
Strings in Python are represented using quotes — either single quotes (' '), double quotes ("
"), or triple quotes (''' ''' / """ """).
2. Which of the following variable names are invalid? Justify.
Variable Valid / Invalid Reason
(a) try Invalid try is a Python keyword, cannot be used as a variable name.
(b) 123Hello Invalid Variable names cannot start with a digit.
(c) sum Valid Although it shadows a built-in function, it is not illegal.
(d) abc@123 Invalid Variable names cannot contain special characters like @.
3. Name four of Python’s basic data types. Why are they called so?
Examples of basic data types:
• int – integers
• float – decimal numbers
• str – strings
• bool – Boolean values (True/False)
They are called basic (or built-in) data types because Python provides them by default, and
they form the fundamental building blocks for handling data.
4. What gets printed?
x = True
y = False
z = False
if x or y and z:
print("yes")
else:
print("no")
Output: yes
Reason: and has higher precedence than or, so expression becomes:
x or (y and z) → True or (False and False) → True.
5. Which numbers are printed?
for i in range(2):
print(i)
for i in range(4, 6):
print(i)
Output:
Explanation
✔ range(2) prints: 0, 1
✔ range(4, 6) prints: 4, 5
6. Define for loops. Write the syntax.
Definition:
A for loop in Python is used to repeat a block of code for each item in a sequence (like a list,
string, or range).
Syntax:
for variable in sequence:
statements
7. Output of the code
a=0
a += 2
print(a)
Output: 2
8. Output of the code
print(3 + 4)
print(3 - 4)
print(3 * 4)
print(3 / 4)
print(3 % 2)
print(3 ** 4)
print(3 // 4)
Output:
-1
12
0.75
81