1) What is docstring in Python?
A Python documentation string is known as docstring, it is a way of documenting Python functions, modules and classes.
2) How can you copy an object in Python?
To copy an object in Python, you can try copy.copy () or copy.deepcopy() for the general case. You cannot copy all objects but most of them.
3) What is negative index in Python?
Python sequences can be index in positive and negative numbers. For positive index, 0 is the first index, 1 is the second index and so forth. For negative index, (-1) is the last index and (-2) is the second last index and so forth.
4) What is module and package in Python?
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.
5) Mention what are the rules for local and global variables in Python?
Local variables: If a variable is assigned a new value anywhere within the function's body, it's assumed to be local.
Global variables: Those variables that are only referenced inside a function are implicitly global.
6) How can you share global variables across modules?
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.
7) Explain how can you make a Python Script executable on Unix?
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)
8) Explain how to delete a file in Python?
By using a command os.remove (filename) or os.unlink(filename)
9) Explain how can you generate random numbers in Python?
To generate random numbers in Python, you need to import command as import random random.random() This returns a random floating point number in the range [0,1)
10) Mention the use of the split function in Python?
The use of the split function in Python is that it breaks a string into shorter strings using the defined separator. It gives a list of all words present in the string.