Professional Python Interview Questions and Answers
Q. What is the difference between Xrange and range?
A. Xrange returns the xrange object while range returns the list, and uses the same memory and no matter what the range size is.
Q. What is module and package in Python?
A. In Python, module is the way to structure program. Each Python program file is a module, which imports other modules like objects and attributes.
The folder of Python program is a package of modules. A package can have modules or subfolders.
Q. How can you share global variables across modules?
A. To share global variables across modules within a single program, create a special module. Import the config module in all modules of your application. The module will be available as a global variable across modules.
Q. Explain how can you make a Python Script executable on Unix?
A. To make a Python Script executable on Unix, you need to do two things,
Script file's mode must be executable and
the first line must begin with#(#!/usr/local/bin/python).