1. Define Python Interpreter.
The Python Interpreter is the program that executes Python code. It reads Python
source code line by line, translates it into bytecode, and executes it. It allows interactive
execution (via the Python shell) as well as running scripts.
2. What is the difference between identifiers and keywords in Python?
Identifiers are user-defined names for variables, functions, classes, etc. Examples: x,
sum, MyClass.
Keywords are reserved words with predefined meanings in Python and cannot be used
as identifiers. Examples: if, while, def, return.
3. Explain the use of the type() function in Python.
The type() function returns the data type of an object.
Example:
print(type(10)) #
print(type(10.5)) #
print(type('Hello')) #
4. What is operator precedence? Give an example.
Operator precedence defines the order in which operators are evaluated in an
expression.
Example: result = 10 + 2 * 3 → result = 16, because * has higher precedence than +.
5. What is the difference between print() and eval() functions?
print(): Displays output on the screen.
eval(): Evaluates a string expression and returns the result.
Example: print(2+3) → 5, eval('2+3') → 5.
6. Write in brief about infinite loops.
An infinite loop runs endlessly because its condition never becomes false.
Example:
while True:
print('This is an infinite loop')
7. What is the use of break and continue statements?
break: Exits the loop immediately.
continue: Skips the current iteration and goes to the next.
Example:
for i in range(5):
if i==3: break
print(i)
8. What is recursion?
Recursion is a technique where a function calls itself to solve a problem.
Example: factorial using recursion:
def fact(n):
if n==0: return 1
return n*fact(n-1)
print(fact(5)) → 120
9. What is the difference between parameters and arguments?
Parameters: Variables defined inside function definition.
Arguments: Actual values passed to the function when it is called.
Example:
def greet(name): # 'name' is parameter
print('Hello', name)
greet('Ahamad') # 'Ahamad' is argument
10. Explain the features of Python programming language.
Features:
- Easy to learn and read
- Interpreted and dynamically typed
- Portable and open source
- Supports OOP, functional and procedural programming
- Large standard library
- Extensible and embeddable
11. Describe different looping constructs in Python with examples.
1. for loop:
for i in range(5): print(i)
2. while loop:
i=0
while i<5:
print(i)
i+=1
3. Nested loops: loop inside another loop.
12. Write a Python program to find the largest among three numbers using if-elif-else.
a=int(input('Enter first number: '))
b=int(input('Enter second number: '))
c=int(input('Enter third number: '))
if a>=b and a>=c:
print('Largest is:', a)
elif b>=a and b>=c:
print('Largest is:', b)
else:
print('Largest is:', c)
13. Explain different types of functions in Python with suitable examples.
1. Built-in functions: Predefined (len(), max(), print())
2. User-defined functions: Defined using def
3. Anonymous (lambda) functions: Defined without name
4. Recursive functions: Functions that call themselves
14. Explain about writing and executing python scripts.
Write: Save script with .py extension (e.g., [Link]).
Execute: Run using command line → python [Link]
Or use IDE (VS Code, PyCharm, IDLE).
15. Write an essay on Python functions. Explain recursion and global variables with
examples.
Functions: Reusable code blocks defined using def.
Types: Built-in, user-defined, lambda, recursive.
Recursion: Function calls itself.
Example: factorial function.
Global variables: Declared outside functions, accessible everywhere.
Example:
x=10
def show():
global x
x+=5
print('Inside function:', x)
show()
print('Outside function:', x)