Questions and Answers Latest Update
Graded A+
How do you create a dictionary in Python?
✔✔You create a dictionary by using curly braces `{}` with key-value pairs. Example: `my_dict
= {"name": "Alice", "age": 25}`.
What does the `type()` function do in Python?
✔✔The `type()` function returns the type of an object.
How can you check if a key exists in a dictionary?
✔✔You can use the `in` keyword to check if a key exists. Example: `"name" in my_dict` returns
`True`.
What does the `range()` function do in Python?
✔✔The `range()` function generates a sequence of numbers, which can be used in a loop.
How do you import a module in Python?
1
, ✔✔You can import a module by using the `import` keyword. For example: `import math`.
What is the purpose of the `else` clause in a loop in Python?
✔✔The `else` clause in a loop is executed when the loop has finished iterating without
encountering a `break` statement.
How do you concatenate two strings in Python?
✔✔You concatenate two strings using the `+` operator. Example: `full_name = "John" + " " +
"Doe"`.
What is the difference between `==` and `is` in Python?
✔✔The `==` operator checks if two values are equal, while `is` checks if two variables point to
the same object in memory.
How can you remove an item from a list in Python?
✔✔You can remove an item from a list using the `remove()` method. Example:
`my_list.remove("item")`.
How do you handle exceptions in Python?
2