SOOPRO Pathshala provides Python Interview Questions and Answers
Python was created and first released in 1991 by Guido van Rossum
Python is a high-level, general-purpose programming language. Python is a programming language that may be used to create desktop GUI apps, websites, and online applications.
In Python, a namespace is a system that assigns a unique name to each and every object
PYTHONPATH is an environment variable that allows the user to add additional folders to the sys.path directory list for Python. In a nutshell, it is an environment variable that is set before the start of the Python interpreter.
Pandas is an open-source python library that has a very rich set of data structures for data-based operations. Pandas with their cool features fit in every role of data operation, whether it be academics or solving complex business problems. Pandas can deal with a large variety of files and are one of the most important tools to have a grip on.
The Python Enhancement Proposal, also known as PEP 8, is a document that provides instructions on how to write Python code. In essence, it is a set of guidelines for formatting Python code for maximum readability. Guido van Rossum, Barry Warsaw, and Nick Coghlan wrote it in 2001.
The zip() function in Python returns a zip object that maps an identical index across multiple containers. It takes an iterable, transforms it into an iterator, and then uses the passed iterables to combine the elements. It returns a tuple iterator.
Iterating a collection of elements, similar to a list, in Python is accomplished with iterators. Iterators can be lists, tuples, or dictionaries-the collection of items. To iterate over the stored elements, Python iterator uses the __itr__ and next() methods. In Python, we for the most part use circles to emphasize over the assortments (list, tuple).
A built-in data type is the Python dictionary. A one-to-one relationship between keys and values is established by this. A pair of keys and their values are contained in dictionaries. It stores components in key and worth matches. Values can be duplicated, whereas keys are unique. The dictionary elements are accessed by the key.
Python has a private heap space that stores all the objects. The Python memory manager regulates various aspects of this heap, such as sharing, caching, segmentation, and allocation. The user has no control over the heap; only the Python interpreter has access.
To generate random numbers in Python, you must first import the random module.
The ‘is’ operator compares the id of the two objects.
The pass statement is used when there's a syntactic but not an operational requirement.
Python has an inbuilt method isalnum() which returns true if all characters in the string are alphanumeric.
The replace() function can be used with strings for replacing a substring with a given string.
Lists are mutable while tuples are immutable.
The split() function splits a string into a number of strings based on a specific delimiter.
A numpy array is a grid of values, all of the same type, and is indexed by a tuple of non-negative integers. The number of dimensions determines the rank of the array. The shape of an array is a tuple of integers giving the size of the array along each dimension.
A matrix comes from linear algebra and is a two-dimensional representation of data.
An array is a sequence of objects of similar data type.
Although Python can be used to write scripts, it is primarily used as a general-purpose programming language.
Any programming language that is not in machine-level code before runtime is called an interpreted language. Python is thus an interpreted language.
Decorators are used for changing the appearance of a function without changing its structure. Decorators are typically defined prior to the function they are enhancing.
Decorators are typically defined prior to the function they are enhancing. To use a decorator, we must first specify its function. Then we write the function to which it is applied, simply placing the decorator function above the function to which it must be applied.
The .py files are the source code files for Python. The bytecode of the python files are stored in .pyc files, which are created when code is imported from another source. The interpreter saves time by converting the source .py files to .pyc files.
Slicing is a technique for gaining access to specific bits of sequences such as strings, tuples, and lists.
Local Variables:
A local variable is any variable declared within a function. This variable exists only in local space, not in global space.
Global Variables:
Global variables are variables declared outside of a function or in a global space. Any function in the program can access these variables.
Yes, Python is case sensitive.
Script file should start with #!/usr/bin/env python
Self is used to represent the class instance. In Python, you can access the class's attributes and methods with this keyword.
For primitive data types, a literal in Python source code indicates a fixed value.
_init_ is a constructor or method in Python. This method is used to allocate memory when a new object is created.
A lambda function is a type of anonymous function. This function can take as many parameters as you want, but just one statement.
Iterators are things that can be iterated through or traversed.
The Pickle module takes any Python object and converts it to a string representation, which it then dumps into a file using the dump method. This is known as pickling.
Unpickling is the process of recovering original Python objects from a stored text representation.
Functions which return an iterable set of items are known as generators.
Use command os.remove(file_name) to delete a file in Python.
The lower() function can be used to convert a string to lowercase.
Dictionary is one of Python's built-in datatypes. It establishes a one-to-one correspondence between keys and values. Dictionary keys and values are stored in pairs in dictionaries. Keys are used to index dictionaries.
The Ternary operator is the operator for displaying conditional statements. This is made of true or false values and a statement that must be evaluated.
The append(), extend(), and insert (i,x) procedures can be used to add elements to an array.
The pop() and remove() methods can be used to remove elements from an array. The difference between these two functions is that one returns the removed value while the other does not.
A Python library is a group of Python packages. Numpy, Pandas, Matplotlib, Scikit-learn, and many other Python libraries are widely used.
In Python, the split() function is used to split a string.
The class keyword in Python is used to construct a class.
A dataframe is a 2D changeable and tabular structure for representing data with rows and columns labelled.
Monkey patches are solely used in Python to run-time dynamic updates to a class or module.
The import keyword can be used to import modules.
Inheritance allows for code reuse, making it easier to develop and maintain applications.
Single
Multilevel
Multiple
Hierarchical
A class can be inherited from multiple parent classes, which is known as multiple inheritance. In contrast to Java, Python allows multiple inheritance.
The ability to take various forms is known as polymorphism.
Encapsulation refers to the joining of code and data. Encapsulation is demonstrated through a Python class.
Only the necessary details are provided, while the implementation is hidden from view. Interfaces and abstract classes can be used to do this in Python.
A class that has no code defined within its block is called an empty class. The pass keyword can be used to generate it. You can, however, create objects of this class outside of the class. When used in Python, the PASS command has no effect.
It produces a featureless object that serves as the foundation for all classes. It also does not accept any parameters.
The term GIL stands for Global Interpreter Lock. This is a mutex that helps thread synchronization by preventing deadlocks by limiting access to Python objects. GIL assists with multitasking (and not parallel computing).
PIP denotes Python Installer Package. It is used to install various Python modules. It's a command-line utility that creates a unified interface for installing various Python modules
Django has a session feature that allows you to store and retrieve data for each site visitor. Django isolates the process of sending and receiving cookies by keeping all necessary data on the server-side and inserting a session ID cookie on the client-side.
An operator is a symbol that is applied to a set of values to produce a result. An operator manipulates operands.
Bitwise operators
Identity operators
Membership operators
Logical operators
Assignment operators
Relational operators
Arithmetic operators
The old Unicode type has been replaced with the "str" type in Python 3, and the string is now considered Unicode by default. Using the art.title.encode("utf-8") function, we can create a Unicode string.
Python includes the smtplib and email libraries for sending emails. Import these modules into the newly generated mail script and send mail to users who have been authenticated.
No
There are four joins in Pandas: left, inner, right, and outer.
The type and fields of the dataframes being merged determine how they are merged. If the data has identical fields, it is combined along axis 0, otherwise, it is merged along axis 1.
We may get the top five entries of a data frame using the head(5) method. df.head() returns the top 5 rows by default. df.head(n) will be used to fetch the top n rows.
We may get the top five entries of a dataframe using the tail(5) method. df.tail() returns the top 5 rows by default. df.tail(n) will be used to fetch the last n rows.
Any data point's class is predicted using a classifier. Classifiers are hypotheses that are used to assign labels to data items based on their classification.
del removes all elements of a list within a given range.
remove() removes the first occurrence of a particular character
append() adds an element to the end of the list
extend() adds elements from an iterable to the end of the list.
To use print() without adding a newline at the end in Python, you can set the end parameter to an empty string (""). By default, print() adds a newline after printing, but using the end argument modifies this behavior.
An interpreted language is any programming language which is not in machine-level code before runtime. Therefore, Python is an interpreted language.
Global Variables:
Variables declared outside a function or in global space are called global variables. These variables can be accessed by any function in the program.
Local Variables:
Any variable declared inside a function is known as a local variable. This variable is present in the local space and not in the global space.
Self is an instance or an object of a class. In Python, this is explicitly included as the first parameter.
Pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.
Functions that return an iterable set of items are called generators.
In Python, the capitalize() method capitalizes the first letter of a string. If the string already consists of a capital letter at the beginning, then, it returns the original string.
The Ternary operator is the operator that is used to show the conditional statements. This consists of the true or false values with a statement that has to be evaluated for it.
Python packages are namespaces containing multiple modules.
To delete a file in Python, you need to import the OS Module. After that, you need to use the os.remove() function.
Python is an object-oriented programming language. This means that any program can be solved in python by creating an object model. However, Python can be treated as a procedural as well as structural language.
Python libraries are a collection of Python packages. Some of the majorly used python libraries are – Numpy, Pandas, Matplotlib, Scikit-learn and many more.
The split() method is used to separate a given String in Python.
Class in Python is created using the class keyword.
In Python, the term monkey patch only refers to dynamic modifications of a class or module at run-time.
Multiple inheritance means that a class can be derived from more than one parent classes. Python does support multiple inheritance, unlike Java.
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.
Encapsulation means binding the code and the data together. A Python class in an example of encapsulation.
Data Abstraction is providing only the required details and hiding the implementation from the world. It can be achieved in Python by using interfaces and abstract classes.
Python does not deprive access to an instance variable or function. Python lays down the concept of prefixing the name of the variable, function or method with a single or double underscore to imitate the behavior of protected and private access specifiers.
An empty class is a class that does not have any code defined within its block. It can be created using the pass keyword. However, you can create objects of this class outside the class itself. IN PYTHON THE PASS command does nothing when its executed. it’s a null statement.
It returns a featureless object that is a base for all classes. Also, it does not take any parameters.
You can modify a DataFrame’s row and column index using reindexing in Pandas. Indexes can be used with reference to many index DataStructure associated with several pandas series or pandas DataFrame.
To eliminate the whitespaces and following spaces from the string, Python provides strip([str]) worked in capability. After removing any whitespaces that may be present, this function returns a copy of the string. If not, returns the original string.
The given string or array is shuffled using this technique. The items in the array become random as a result. The random module includes this method. Therefore, we must import it before calling the function. It rearranges components each time when the capability calls and creates different result.
An operator is a specific symbol that is applied to some values and results in an output. Operands are the work of an operator. Operands are literals or variables with numbers that have some values. Administrators can be unary, double, or ternary.
In Python 3, the old Unicode type has been replaced by "str" type, and the string is treated as Unicode of course. Using the art.title.encode("utf-8") function, we can create a Unicode string.
The enumerate() function is used to iterate through the sequence and retrieve the index position and its corresponding value at the same time.
A lambda function is a small function that is defined anonymously by the keyword 'lambda'. It can have any number of arguments and it can only have one expression. Lambda functions are frequently used instead of the full 'def' statement when a function definition is very simple and not complicated enough.