1.

What happens when you import a module Python?

Answer»

When a module is imported in Python, the following happens behind the scenes:
It starts with searching for mod.py in a list of directories which have been gathered from the following sources:

  • The original directory from where the input script was actually being run or in the current list if the interpreter is being run interactively side by side.
  • List of the directories within the PYTHONPATH environment variable, if it is actually set.
  • A directory list from the installed directories would have been configured at the time of installation of Python itself.

Note: After learning the basics of Python, if you are looking for what more to learn, you can start with meta-programming, buffering protocols, iterator protocols, and much more. We have created a list of Python INTERVIEW Questions for Experienced professionals to help them USE this language to solve complex problems.

27. How do you use range in Python?

The range() is an in-built function in Python, which is used to repeat an action for a specific number of times.

Let US give you an example to demonstrate how the range() function works:

Example

SUM = 0
for i in range(1, 11):
    sum = sum + i
print("Sum of first 10 number :", sum)

Output:

Sum of first 10 number: 55



Discussion

No Comment Found