Python Questions Answers
Python Questions Answers
1) Explain the features of Python that make it a popular choice for various applications.
Python is easy to learn and use, has extensive libraries, supports multiple programming paradigms,
is portable, dynamically typed, and has strong community support.
2) Describe the role of variables in Python. How are they declared and assigned values?
Variables store data. In Python, variables are created when assigned a value. Example:
x = 10
name = 'Python'
pi = 3.14
3) List and explain any 4 commonly used built-in functions in Python for console input and
output operations.
Conditional Statements (if-else), Loops (for, while), and Exception Handling (try-except) control the
flow of execution.
5) Discuss the various operators in Python and their precedence and association rules.
Python has arithmetic, comparison, logical, bitwise, and assignment operators. Precedence order:
1. Parentheses (), 2. Exponentiation **, 3. Multiplication *, 4. Addition +, 5. Comparison ==, 6.
Logical and, or.
A=5+2*3-4/2=9
B = (4+5) * 3/2 - 1 = 12.5
C = 10/2 * 2 + 5 * 2 - 4 = 16
D = (10-3) * 2 / (5-2) = 4.67
7) Write a Python program where a user needs to find the sum of all even numbers between 1
and a given number.
for i in range(10):
if i == 5:
break
print(i) # Stops when i reaches 5
2) What is an interpreter?
An interpreter executes code line by line, unlike a compiler. Python is an interpreted language.