Graded A+
What is Python used for in programming?
✔✔Python is used for web development, data analysis, artificial intelligence, automation, and
more.
How do you print text to the console in Python?
✔✔You use the `print()` function to display text in the console.
What happens if you don’t indent properly in Python?
✔✔Python will raise an IndentationError because indentation is crucial for defining code blocks.
How do you store multiple items of the same type in Python?
✔✔You can use a list to store multiple items of the same type.
Why is Python called a high-level programming language?
✔✔Python is called a high-level language because it is closer to human language and abstracts
complex machine-level details.
1
,How do you calculate the area of a circle in Python?
✔✔You can calculate it using the formula `area = 3.14 * radius ** 2`.
What is the output of `print(5 // 2)` in Python?
✔✔The output is `2` because `//` performs floor division, which discards the decimal part.
How do you swap the values of two variables in Python?
✔✔You swap them using `a, b = b, a`.
What happens if you try to divide by zero in Python?
✔✔Python will raise a `ZeroDivisionError`.
How can you make your program wait for a few seconds in Python?
✔✔You use the `time.sleep()` function after importing the `time` module.
What is the purpose of `__init__` in a Python class?
✔✔The `__init__` method initializes an object’s attributes when it is created.
2
, How do you make a Python loop run a specific number of times?
✔✔You use a `for` loop with the `range()` function.
What is the output of `print("Python" * 3)`?
✔✔The output is `PythonPythonPython` because the `*` operator repeats strings.
How do you check if a string starts with a specific character?
✔✔You use the `startswith()` method, like `string.startswith('P')`.
What does `print(len([1, 2, 3, 4]))` return?
✔✔It returns `4` because `len()` gives the number of elements in the list.
How do you reverse a string in Python?
✔✔You reverse a string using slicing like `string[::-1]`.
What is the difference between mutable and immutable objects in Python?
3