-
What is a variadic function ?
- answer:
- A variadic function is a function that can take a variable number of arguments.
-
What does a function pointer allow us to do ?
- answer: A function pointer allow us to:
- Call a function through a pointer.
- Pass a function as an argument to another.
-
What is __str__
in Python ?
- Answer:
- It is a special method used to define a string representation of an object.
- It is called when you use the
str()
function or when you print an object.
- It returns a human-readable, of informal, string representation of an object.
-
What is a class ?
- Answer:
- A class is a blueprint for creating objects (instances).
- It encapsulates data (attributes) and behaviors (methods) that objects of the class can have.
-
Can you catch multiple exceptions in a single except block ?
-
Answer:
- Yes, you can catch multiple exceptions using parentheses, example:
try:
# Some code
except (TypeError, ValueError) as e:
print(e)
-
Are lists mutable or immutable in Python ?
- Answer:
- Lists are mutable, meaning their contents can be changed after creation.
-
What happens if you try to modify an immutable object like a string for example ?
- Answer:
- You can't modify the original string. Any operation that seems to "modify" a string will actually return a new string.
-
What is the primary idea behind Test-Driven Development (TDD) and its benefit ?
- Answer:
- TDD is a development approach where you write tests before writing the actual code.
- The cycle follows: write a failing test, write code to pass the test, then refactor.
- TDD ensures code is more reliable, helps catch bugs early, and leads to better structured and maintainable code.
-
**What is the __dict_**_
method in Python ?
- Answer:
- The
__dict__
attribute is a dictionary that contains all the writable attributes of an object. It shows the internal state of an object as key-value pairs.