1. What is Python?
Answer:
Python is a high-level, interpreted, and general-purpose programming language
that emphasizes readability and simplicity. It supports multiple programming
paradigms, including procedural, object-oriented, and functional programming.
Python is widely used in web development, data science, automation, artificial
intelligence, and more.
2. What are the different data types in Python?
Answer:
Python has several built-in data types:
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Text Type: str
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
None Type: NoneType
3. What is the difference between list and tuple in Python?
Answer:
List: A list is a mutable, ordered collection of items. Lists allow
modifications (adding, removing, or changing elements).
Tuple: A tuple is an immutable, ordered collection of items. Once created,
the elements of a tuple cannot be modified.
, Example:
# List example
my_list = [1, 2, 3]
my_list[0] = 10 # Works fine
# Tuple example
my_tuple = (1, 2, 3)
my_tuple[0] = 10 # Error: 'tuple' object does not support item assignment
4. What are Python's control flow statements?
Answer:
Python supports the following control flow statements:
if: Used to execute code conditionally.
for: Used to iterate over sequences (like lists, tuples, or ranges).
while: Used to execute code as long as a condition is true.
break: Exits the loop prematurely.
continue: Skips the current iteration and moves to the next iteration.
else: Executes code when no condition is met in loops or after if
statements.
Example:
# If-Else
if x > 10:
print("Greater than 10")
else:
print("Less than or equal to 10")
5. What is a function in Python?
Answer:
A function in Python is a block of reusable code that performs a specific task.