/    /  Python – Interview Questions Part 6

1. Explain how can you access a module written in Python from C?

Answer: By using the below method we can access a module written in Python from C

Module = =PyImport_ImportModule(“<modulename>”);


2. Explain what is the common way for the Flask script to work?

Answer: The common way for the flask script to work is either it should be the import path for your application or the path to a Python file.


3. Mention the use of the split function in Python?

Answer: The split function in python is used to break a string into shorter strings using the defined separator and also gives a list of all words present in the string.

>>>4 5 6 7



Output-: [4,5,6,7]


4. Mention the use of // operator in Python?

Answer: An // operator is used for Floor Division operator , which is used for dividing two operands with the result as quotient showing only digits before the decimal point.


5. Explain how can you make a Python Script executable on Unix?

Answer: It involves with 2 things.

1. Script file’s mode must be executable and

2. The first line must begin with # ( #!/usr/local/bin/python)


6. How are arguments passed by value or by reference?

Answer: Python is an object and all variables hold references to the objects. If reference values are according to the functions; then the result you cannot change. Hence, you can change the objects if it is mutable.


7.  How will you share global variables across modules?

Answer: By a single program we can share global variables across modules by creating a special module.

Import the config module in all modules of your application.

The module will be available as a global variable across modules.


8. Mention what are the rules for local and global variables in Python?

Answer: 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.


9. What is module and package in Python?

Answer: A module is the way to structure program. Each and every Python program file is a module, which imports other modules like objects and attributes. Package of modules  are the Python program folders . A package can have modules or subfolders.


10. Is Flask an MVC model ?

Answer: Flask is a minimalistic framework which behaves same as MVC framework. So MVC is a perfect fit for Flask, and the pattern for MVC