New 1
New 1
{
"question": "What is a variable in Python?",
"answer": "A variable in Python is a name used to store a value. It acts as
a placeholder for data that can be changed later."
},
{
"question": "How do you declare a function in Python?",
"answer": "In Python, you can declare a function using the `def` keyword.
For example: `def my_function():`."
},
{
"question": "What is a class in Python?",
"answer": "A class in Python is a blueprint for creating objects. It
defines a set of attributes and methods that the objects created from the class can
use."
},
{
"question": "What is the difference between a list and a tuple in Python?",
"answer": "The main difference is that lists are mutable, meaning their
elements can be changed, while tuples are immutable and cannot be modified after
creation."
},
{
"question": "How do you handle exceptions in Python?",
"answer": "Exceptions in Python can be handled using the `try`, `except`,
and optionally `finally` blocks. For example: `try: x = 1 / 0 except
ZeroDivisionError: print('Cannot divide by zero!')`."
},
{
"question": "What is an object in Object-Oriented Programming?",
"answer": "An object is an instance of a class. It contains both data
(attributes) and functions (methods) that act on the data."
},
{
"question": "How do you comment code in Python?",
"answer": "In Python, you can add a single-line comment using the `#`
symbol. For multi-line comments, you can use triple quotes (`'''` or `\"\"\"`)."
},
{
"question": "What is the difference between `==` and `is` in Python?",
"answer": "`==` checks for value equality, while `is` checks for identity
equality (whether two variables point to the same object in memory)."
},
{
"question": "What is a Python decorator?",
"answer": "A Python decorator is a function that modifies the behavior of
another function or method. Decorators are applied using the `@decorator_name`
syntax."
},
{
"question": "How do you install a Python library?",
"answer": "You can install a Python library using the `pip` package
manager. For example: `pip install library_name`."
}
]