Python FAQs

What is Python?

Python is an Object-Oriented Programming language.

Is Python pure object-oriented?

No, Python is not pure object-oriented because it doesn't support strong encapsulation feature.

Difference between list and tuple?
List Tuple
List is collection of mutable items, means can be items can be modify. Tuple is collection of immutable items, means can be items cannot modify.
List items are enclosed with square brackets []. Tuple items are enclosed with paranthesis ().
How to create a tuple with the elements read from user at run-time.
l = [int(input()) for i in range(4)]
t = tuple(l)
print(t)
Difference between shallow copy and deep copy.
Shallow Copy Deep Copy
Shallow copy creates a new object which stores the reference of the original elements Deep copy creates a new object and also copies the elements of the original elements
Modifying an element present in one object that reflects in another object.
Example:
l = [2,4,6,8]
dup = l
dup[2] = 7
print(l)
print(dup)
[2, 4, 7, 8]
[2, 4, 7, 8]
Modifying an element in one object doesn't reflects on another.
Example:
l = [2,4,6,8]
dup = l.copy()
dup[2] = 7
print(l)
print(dup)
[2, 4, 6, 8]
[2, 4, 7, 8]
What is the use of pass?

pass keyword represents null operations. It generally used in empty blocks.

What is dictionary in Python?

Dictionary(dict) is a built-in datatype in Python. Dictionary is a collection of key and value pairs. Dictionary value can be indexed with keys.

What are acceptable types for dictionary keys?

Integer, String and Tuple can be allowed as dictionary keys.

What is function? How to define functions in Python?

A function is a self contained block which is executed when it is called. In Python, functions are defined using def keyword.

What is variable-length argument?

A variable-length argument at function definition can hold any number of arguments in single tuple variable.

What is a lambda function?

An anonymous function is known as a lambda function. This function can have any number of parameters but can have one statement only.

What is module in Python?

A module is a Python file that contains variable, functions, classes or runnable code.

What is package?

In Python, package is a collection of modules, classes and functions.

What is PIP?

PIP stands for Preferred Installer Program, which is used to install and manage packages in Python.

What is PEP?

PEP stands for Python Enhancement Proposal, is a set of rules that specify how to format Python code for maximum readability.

What is self?

The self paramenter is a reference of current instance of class used to access variables.