python Flashcards
What is the purpose of the function super() in the subclass?
we can access the parent’s class properties and methods when building the subclass
explain a lambda function in python
A lambda function in Python is a small anonymous function defined using the lambda keyword, typically used for simple operations and as arguments in higher-order functions.
explain a map function in python
The map() function in Python applies a given function to each item of an iterable (such as a list) and returns a new iterable containing the results.
Explain a tuple in python
In Python, a tuple is an immutable, ordered collection of elements enclosed within parentheses, allowing for the storage of multiple items which can be of different data types, accessed by indexing, and used as keys in dictionaries or elements in sets.
What is the difference between / and // in Python
/ represents precise division (result is a floating point number) whereas // represents floor division (result is an integer).
5//2 = 2
5/2 = 2.5
What are *args and *kwargs?
To pass a variable number of arguments to a function in Python, use the special syntax *args and **kwargs in the function specification. It is used to pass a variable-length, keyword-free argument list. By using the *, the variable we associate with the * becomes iterable, allowing you to do operations on it such as iterating over it and using higher-order operations like map and filter.
Does Python supports multiple Inheritance?
Python does support multiple inheritances, unlike Java. Multiple inheritances mean that a class can be derived from more than one parent class.
What is Polymorphism in Python?
Polymorphism means the ability to take multiple forms. So, for instance, if the parent class has a method named ABC then the child class also can have a method with the same name ABC having its own parameters and variables. Python allows polymorphism.
Define encapsulation in Python?
Encapsulation means binding the code and the data together. A Python class is an example of encapsulation.
What is slicing in Python?
Python Slicing is a string operation for extracting a part of the string, or some part of a list. With this operator, one can specify where to start the slicing, where to end, and specify the step. List slicing returns a new list from the existing list.
What is a zip function?
ython zip() function returns a zip object, which maps a similar index of multiple containers. It takes an iterable, converts it into an iterator and aggregates the elements based on iterables passed. It returns an iterator of tuples.
What are Pickling and Unpickling?
The Pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using the dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.
What is monkey patching in Python?
the term monkey patch only refers to dynamic modifications of a class or module at run-time.
What is __init__() in Python?
Equivalent to constructors in OOP terminology, __init__ is a reserved method in Python classes. The __init__ method is called automatically whenever a new object is initiated. This method allocates memory to the new object as soon as it is created. This method can also be used to initialize variables.
What are Access Specifiers in Python?
Python uses the ‘_’ symbol to determine the access control for a specific data member or a member function of a class. A Class in Python has three types of Python access modifiers:
Public Access Modifier: The members of a class that are declared public are easily accessible from any part of the program. All data members and member functions of a class are public by default.
Protected Access Modifier: The members of a class that are declared protected are only accessible to a class derived from it. All data members of a class are declared protected by adding a single underscore ‘_’ symbol before the data members of that class.
Private Access Modifier: The members of a class that are declared private are accessible within the class only, the private access modifier is the most secure access modifier. Data members of a class are declared private by adding a double underscore ‘__’ symbol before the data member of that class.