and Answers with Verified Solutions
What is a variable in Python?
✔✔ A variable in Python is a symbolic name that is used to store data values.
How do you create an empty list in Python?
✔✔ Use empty square brackets, like `empty_list = []`.
How can you concatenate two strings in Python?
✔✔ Use the `+` operator, like `result = "Hello" + " " + "World"`.
What is the difference between `append()` and `extend()` methods in Python?
✔✔ `append()` adds an element to the end of a list, while `extend()` adds multiple elements to a
list.
How do you check if a number is even in Python?
✔✔ Use the modulus operator, like `if num % 2 == 0`.
1
,How do you convert a list to a string in Python?
✔✔ Use the `join()` method, like `''.join(list)`.
What is a tuple in Python?
✔✔ A tuple is an immutable, ordered collection of elements.
How do you access the first element of a list?
✔✔ Use indexing, like `my_list[0]`.
What is a function in Python?
✔✔ A function is a block of reusable code that performs a specific task, defined using the `def`
keyword.
What is the difference between `global` and `local` variables in Python?
✔✔ A `global` variable is accessible throughout the program, while a `local` variable is only
accessible within the function where it is defined.
What is the purpose of the `pass` statement in Python?
2
, ✔✔ The `pass` statement is used as a placeholder to indicate that no action is to be taken.
How can you iterate through a dictionary in Python?
✔✔ Use a `for` loop to iterate through the dictionary, like `for key, value in my_dict.items()`.
How do you check if a key exists in a dictionary?
✔✔ Use the `in` operator, like `if key in my_dict`.
What is a class in Python?
✔✔ A class is a blueprint for creating objects that define properties and methods.
How do you inherit from a class in Python?
✔✔ Use parentheses to specify the parent class when defining a new class, like `class
ChildClass(ParentClass):`.
What is a lambda function in Python?
✔✔ A lambda function is a small anonymous function defined using the `lambda` keyword.
3