Top Python Interview Question(2022) || python interview question and answers || python interview questions and answers for freshers - Creation Code
Top Python Interview Question You Must Know
What are local variables and global variables in Python?
Global Variables:
Variables declared outside a function or in a 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.
Example:
1
2
3
4
5
6
a=2
def add():
b=3
c=a+b
print(c)
add()
What is PYTHONPATH?
Ans: It is an environment variable that 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.
What is _init_?
Ans: _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.
What are the generators in python?
Ans: Functions that return an iterable set of items are called generators
Comments
Post a Comment