Before we understand a dynamically typed language, we should learn about what typing is. Typing refers to type-checking in programming languages. In a strongly-typed language, such as Python, "1" + 2 will result in a type error since these languages don't allow for "type-coercion".
Type-checking can be done at two stages:
• Static - Data Types are checked before execution.
• Dynamic - Data Types are checked during execution.
Python is an interpreted language, executes each statement line by line and thus type-checking is done on the fly, during execution. Hence, Python is a Dynamically Typed Language.
An Interpreted language executes its statements line by line. Languages such as Python, Javascript, R, PHP, and Ruby are prime examples of Interpreted languages. Programs written in an interpreted language runs directly from the source code, with no intermediary compilation step.
A Pass statement in Python is used when we cannot decide what to do in our code, but we must type something for making syntactically correct.
Yes, runtime errors exist in Python. For example, if you are duck typing and things look like a duck, then it is considered as a duck even if that is just a flag or stamp or any other thing. The code, in this case, would be A Run-time error. For example, Print “Hackr io”, then the runtime error would be the missing parenthesis that is required by print ( ).
No Python does not support an intrinsic do-while loop.
We need membership operators in Python with the purpose to confirm if the value is a member in another or not.
In order to compile new extensions without any error, compiling and linking is used in Python. Linking initiates only and only when the compilation is complete. In the case of dynamic loading, the process of compilation and linking depends on the style that is provided with the concerned system. In order to provide dynamic loading of the configuration setup files and rebuilding the interpreter, the Python interpreter is used.
The Pickle module in Python allows accepting any object and then converting it into a string representation. It then dumps the same into a file by means of the dump function. This process is known as pickling. The reverse process of pickling is known as unpickling i.e. retrieving original Python objects from a stored string representation.
Upon exiting, Python’s built-in effective cleanup mechanism comes into play and try to deallocate or destroy every other object. However, Python modules that are having circular references to other objects or the objects that are referenced from the global namespaces aren’t always deallocated or destroyed. This is because it is not possible to deallocate those portions of the memory that are reserved by the C library.
All of the Python is an object and all variables hold references to the object. The reference values are according to the functions; as a result, the value of the reference cannot be changed.
Slicing refers to the mechanism to select the range of items from sequence types like lists, tuples, strings.
Docstring is a Python documentation string, it is a way of documenting Python functions, classes and modules.
Decorators are used to add some design patterns to a function without changing its structure. Decorators generally are defined before the function they are enhancing. To apply a decorator we first define the decorator function. Then we write the function it is applied to and simply add the decorator function above the function it has to be applied to. For this, we use the @ symbol before the decorator.
Slicing is used to access parts of sequences like lists, tuples, and strings. The syntax of slicing is-[start:end:step]. The step can be omitted as well. When we write [start:end] this returns all the elements of the sequence from the start (inclusive) till the end-1 element. If the start or end element is negative i, it means the ith element from the end. The step indicates the jump or how many elements have to be skipped. Eg. if there is a list- [1,2,3,4,5,6,7,8]. Then [-1:2:2] will return elements starting from the last element till the third element by printing every second element.i.e. [8,6,4].
A literal in python source code represents a fixed value for primitive data types.
There are 4 types of literals in python-
• String literals– A string literal is created by assigning some text enclosed in single or double quotes to a variable. To create multiline literals, assign the multiline text enclosed in triple quotes. Eg.name="Tanya"
• A character literals– It is created by assigning a single character enclosed in double quotes. Eg. a='T'
• Numeric literals– They include numeric values that can be either integer, floating point value, or a complex number. Eg. a=50
• Boolean literals– These can be 2 values- either True or False.
The dataframes in python can be combined in the following ways-
• Concatenating them by stacking the 2 dataframes vertically.
• Concatenating them by stacking the 2 dataframes horizontally.
• Combining them on a common column. This is referred to as joining.
The concat() function is used to concatenate two dataframes. Its syntax is- pd.concat([dataframe1, dataframe2]).
The new features in Python 3.9.0.0 version are-
• New Dictionary functions Merge(|) and Update(|=)
• New String Methods to Remove Prefixes and Suffixes
• Type Hinting Generics in Standard Collections
• New Parser based on PEG rather than LL1
• New modules like zoneinfo and graphlib
• Improved Modules like ast, asyncio, etc.
• Removal of erroneous methods, functions, etc.
Memory is managed in Python in the following ways:
• Memory management in python is managed by Python private heap space. All Python objects and data structures are located in a private heap. The programmer does not have access to this private heap. The python interpreter takes care of this instead.
• The allocation of heap space for Python objects is done by Python’s memory manager. The core API gives access to some tools for the programmer to code.
• Python also has an inbuilt garbage collector, which recycles all the unused memory and so that it can be made available to the heap space.
A namespace is a naming system used to make sure that names are unique to avoid naming conflicts.
A function is a block of code which is executed only when it is called. To define a Python function, the def keyword is used.
__init__ is a method or constructor in Python. This method is automatically called to allocate memory when a new object/ instance of a class is created. All classes have the __init__ method.
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 is an environment variable which is used when a module is imported. Whenever a module is imported, PYTHONPATH is also looked up to check for the presence of the imported modules in various directories. The interpreter uses it to determine which module to load.
Indentation is necessary for Python. It specifies a block of code. All code within loops, classes, functions, etc is specified within an indented block. It is usually done using four space characters. If your code is not indented necessarily, it will not execute accurately and will throw errors as well.
Django is more popular because it has plenty of functionality out of the box, making complicated applications easier to build. Django is best suited for larger projects with a lot of features. The features may be overkill for lesser applications. If you’re new to web programming, Flask is a fantastic place to start. Many websites are built with Flask and receive a lot of traffic, although not as much as Django-based websites. If you want precise control, you should use flask, whereas a Django developer relies on a large community to produce unique websites.
Merging depends on the type and fields of different dataframes being merged. If data is having similar fields data is merged along axis 0 else they are merged along axis 1.
By using tail(5) function we can get the top five entries of a dataframe. By default df.tail() returns the top 5 rows. To get the last n rows df.tail(n) will be used.
Comments in Python refer to a piece of text intended for information. It is especially relevant when more than one person works on a set of codes. It can be used to analyse code, leave feedback, and debug it. There are two types of comments which includes:
• Single-line comment
• Multiple-line comment
A classifier is used to predict the class of any data point. Classifiers are special hypotheses that are used to assign class labels to any particular data points. A classifier often uses training data to understand the relation between input variables and the class. Classification is a method used in supervised learning in Machine Learning.
One of the ways we can get a list of keys is by using: dict.keys()
This method returns all the available keys in the dictionary.
dict = {1:a, 2:b, 3:c} dict.keys()
o/p: [1, 2, 3]
List comprehensions are used for transforming one list into another list. Elements can be conditionally included in the new list and each element can be transformed as needed. It consists of an expression leading a for clause, enclosed in brackets.
for ex: list = [i for i in range(1000)]
print list
The bytes() function returns a bytes object. It is used to convert objects into bytes objects, or create empty bytes object of the specified size.
“with” statement in python is used in exception handling. A file can be opened and closed while executing a block of code, containing the “with” statement, without using the close() function. It essentially makes the code much more easy to read.
One major difference between a tuple and a dictionary is that dictionary is mutable while a tuple is not. Meaning the content of a dictionary can be changed without changing it’s identity, but in tuple that’s not possible.
The new modifier is used to instruct the compiler to use the new implementation and not the base class function.
The Override modifier is useful for overriding a base class function inside the child class.
You worked hard on your resume and job application, and now you are called in for an in-person job interview. You are one step closer to your dream job. It’s time to understand how to succeed in the job interview, so that you can actually land the job. Here are the most important things you have to remember.