Certified Solutions
What is Python famous for?
✔✔Its simplicity, readability, and versatility across different fields like AI, web development,
and automation.
Why does Python not require explicit declaration of variable types?
✔✔Because it is a dynamically typed language that determines types at runtime.
What does the `append()` method do in Python?
✔✔It adds an item to the end of a list.
What is the purpose of the `for` loop in Python?
✔✔To iterate over a sequence, such as a list, tuple, or string.
How do you handle exceptions in Python?
✔✔By using the `try` and `except` blocks.
1
,What is the difference between `is` and `==` in Python?
✔✔`is` checks for identity (if two objects are the same), while `==` checks for equality (if their
values are the same).
How do you convert a string to an integer in Python?
✔✔By using the `int()` function, e.g., `int("10")`.
What is the purpose of the `import` statement in Python?
✔✔It is used to include external libraries or modules in your code.
How can you make a string all uppercase in Python?
✔✔By using the `upper()` method, e.g., `"hello".upper()`.
What is the significance of indentation in Python?
✔✔Indentation defines the structure of the code and is mandatory for blocks like loops and
functions.
What does the `range()` function do in Python?
2
,✔✔It generates a sequence of numbers, often used in loops.
How do you create a class in Python?
✔✔By using the `class` keyword, e.g., `class MyClass:`.
What is the purpose of the `self` keyword in Python classes?
✔✔It represents the instance of the class and is used to access its attributes and methods.
What does `break` do inside a loop?
✔✔It immediately exits the loop, skipping the remaining iterations.
How do you check if an element exists in a list?
✔✔By using the `in` keyword, e.g., `if x in my_list`.
What is the difference between `pop()` and `remove()` in a list?
✔✔`pop()` removes an element by index and returns it, while `remove()` deletes an element by
value.
3
, How do you read a file in Python?
✔✔By using the `open()` function with a mode, such as `r` for reading, e.g., `open("file.txt",
"r")`.
What does the `map()` function do in Python?
✔✔It applies a function to each item in an iterable and returns a map object.
How do you reverse a list in Python?
✔✔By using the `reverse()` method or slicing, e.g., `my_list[::-1]`.
What is the purpose of the `with` statement in Python?
✔✔It is used to handle resources like files, ensuring they are properly closed after use.
Python is a general-purpose programming language, appropriate for solving problems in many
areas of computing.
True
False ✔✔True
4