1. Tell me what are generators in Python?
The way of implementing iterators are known as generators. It is a normal function except that it yields expression in the function.
2. Tell me what is pickling and unpickling?
Pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.
3. How to 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.
4. Tell me what is the difference between list and tuple?
The difference between list and tuple is that list is mutable while tuple is not. Tuple can be hashed for e.g as a key for dictionaries.
5. Tell me what is docstring in Python?
A Python documentation string is known as docstring, it is a way of documenting Python functions, modules and classes.
6. Explain me what is Python and explain some of its benefits?
Python is a programming language with objects, modules, threads, exceptions and automatic memory management. The benefits of pythons are that it is simple and easy, portable, extensible, build-in data structure and it is an open source.
7. Tell me 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.
8. Explain me what is unittest in Python?
A unit testing framework in Python is known as unittest. It supports sharing of setups, automation testing, shutdown code for tests, aggregation of tests into collections etc.
9. How to convert a number to a string?
In order to convert a number into a string, use the inbuilt function str(). If you want a octal or hexadecimal representation, use the inbuilt function oct() or hex().
10. Do you know how Python is interpreted?
Python language is an interpreted language. Python program runs directly from the source code. It converts the source code that is written by the programmer into an intermediate language, which is again translated into machine language that has to be executed.
11. Explain me what Is The Purpose Of Doc Strings In Python?
In Python, documentation string is popularly known as doc strings. It sets a process of recording Python functions, modules, and classes.
12. How to access sessions in Flask?
A session basically allows you to remember information from one request to another. In a flask, it uses a signed cookie so the user can look at the session contents and modify. The user can modify the session if only it has the secret key Flask.secret_key.
13. Tell me what is Dict and List comprehensions are?
They are syntax constructions to ease the creation of a Dictionary or List based on existing iterable.
14. Explain me five benefits of using Python?
☛ Python comprises of a huge standard library for most Internet platforms like Email, HTML, etc.
☛ Python does not require explicit memory management as the interpreter itself allocates the memory to new variables and free them automatically
☛ Provide easy readability due to use of square brackets
☛ Easy-to-learn for beginners
☛ Having the built-in data types saves programming time and effort from declaring variables
15. Tell me how are arguments passed by value or by reference?
Everything in Python is an object and all variables hold references to the objects. The references values are according to the functions; as a result you cannot change the value of the references. However, you can change the objects if it is mutable.
16. Explain me what Does The <Self> Keyword Do?
The <self> keyword is a variable that holds the instance of an object. In almost, all the object-oriented languages, it is passed to the methods as hidden parameter.
17. Explain me what is Flask-WTF and what are their features?
Flask-WTF offers simple integration with WTForms. Features include for Flask WTF are
☛ Integration with wtforms
☛ Secure form with csrf token
☛ Global csrf protection
☛ Internationalization integration
☛ Recaptcha supporting
☛ File upload that works with Flask Uploads
18. How to access a module written in Python from C?
You can access a module written in Python from C by following method,
Module = =PyImport_ImportModule(“<modulename>”);
19. Tell me how Does Python Handle The Memory Management?
☛ Python uses private heaps to maintain its memory. So the heap holds all the Python objects and the data structures. This area is only accessible to the Python interpreter; programmers can't use it.
☛ And it's the Python memory manager that handles the Private heap. It does the required allocation of the heap for Python objects.
☛ Python employs a built-in garbage collector, which salvages all the unused memory and offloads it to the heap space.
20. Do you know how is memory managed in Python?
☛ Python memory is managed by Python private heap space. All Python objects and data structures are located in a private heap. The programmer does not have an access to this private heap and interpreter takes care of this Python private heap.
☛ The allocation of Python heap space for Python objects is done by Python memory manager. The core API gives access to some tools for the programmer to code.
☛ Python also have an inbuilt garbage collector, which recycle all the unused memory and frees the memory and makes it available to the heap space.
21. Tell me how Do You Debug A Program In Python? Is It Possible To Step Through Python Code?
Yes, we can use the Python debugger (<pdb>) to debug any Python program. And if we start a program using <pdb>, then it let us even step through the code.
list = ['a', 'b', 'c', 'd', 'e']
print (list[10:])
The result of the above lines of code is []. There won't be any error like an IndexError.
You should know that trying to fetch a member from the list using an index that exceeds the member count (for example, attempting to access list[10] as given in the question) would yield an IndexError. By the way, retrieving only a slice at an opening index that surpasses the no. of items in the list won't result in an IndexError. It will just return an empty list.
23. Please explain when Is The Python Decorator Used?
Python decorator is a relative change that you do in Python syntax to adjust the functions quickly.
24. Tell me what Is The Command To Debug A Python Program?
The following command helps run a Python program in debug mode.
$ python -m pdb python-script.py
25. Do you know why lambda forms in python does not have statements?
A lambda form in python does not have statements as it is used to make new function object and then return them at runtime.
26. Tell us 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.
27. How to minimize the Memcached server outages in your Python Development?
☛ • When one instance fails, several of them goes down, this will put larger load on the database server when lost data is reloaded as client make a request. To avoid this, if your code has been written to minimize cache stampedes then it will leave a minimal impact
☛ • Another way is to bring up an instance of Memcached on a new machine using the lost machines IP address
☛ • Code is another option to minimize server outages as it gives you the liberty to change the Memcached server list with minimal work
☛ • Setting timeout value is another option that some Memcached clients implement for Memcached server outage. When your Memcached server goes down, the client will keep trying to send a request till the time-out limit is reached
28. How to delete a file in Python?
By using a command os.remove (filename) or os.unlink(filename)
29. Explain me what is pass in Python?
Pass means, no-operation Python statement, or in other words it is a place holder in compound statement, where there should be a blank left and nothing has to be written there.
30. Tell me why And When Do You Use Generators In Python?
A generator in Python is a function which returns an iterable object. We can iterate on the generator object using the <yield> keyword. But we can only do that once because their values don’t persist in memory, they get the values on the fly.
Generators give us the ability to hold the execution of a function or a step as long as we want to keep it. However, here are a few examples where it is beneficial to use generators.
☛ We can replace loops with generators for efficiently calculating results involving large data sets.
☛ Generators are useful when we don’t want all the results and wish to hold back for some time.
☛ Instead of using a callback function, we can replace it with a generator. We can write a loop inside the function doing the same thing as the callback and turns it into a generator.
31. Tell us which Python Function Will You Use To Convert A Number To A String?
For converting a number into a string, you can use the built-in function <str()>. If you want an octal or hexadecimal representation, use the inbuilt function <oct()> or <hex()>.
32. Explain me what Are The Built-In Types Available In Python?
Here is the list of most commonly used built-in types that Python supports:
☛ Immutable built-in types of Python
Numbers
Strings
Tuples
☛ Mutable built-in types of Python
List
Dictionaries
Sets
33. Explain me what are the key features of Python?
These are the few key features of Python:
☛ Python is an interpreted language. That means that, unlike languages like C and its variants, Python does not need to be compiled before it is run. Other interpreted languages include PHP and Ruby.
☛ Python is dynamically typed, this means that you don't need to state the types of variables when you declare them or anything like that. You can do things like x=111 and then x="I'm a string" without error
☛ Python is well suited to object orientated programming in that it allows the definition of classes along with composition and inheritance. Python does not have access specifiers (like C++'s public, private), the justification for this point is given as “we are all adults here”
☛ In Python, functions are first-class objects. This means that they can be assigned to variables, returned from other functions and passed into functions. Classes are also first class objects
☛ Writing Python code is quick but running it is often slower than compiled languages. Fortunately,Python allows the inclusion of C based extensions so bottlenecks can be optimized away and often are. The numpy package is a good example of this, it's really quite quick because a lot of the number crunching it does isn't actually done by Python
☛ Python finds use in many spheres – web applications, automation, scientific modelling, big data applications and many more. It's also often used as “glue” code to get other languages and components to play nice.
34. Explain me database connection in Python Flask?
Flask supports database powered application (RDBS). Such system requires creating a schema, which requires piping the shema.sql file into a sqlite3 command. So you need to install sqlite3 command in order to create or initiate the database in Flask.
Flask allows to request database in three ways
before_request() : They are called before a request and pass no arguments
after_request() : They are called after a request and pass the response that will be sent to the client
teardown_request(): They are called in situation when exception is raised, and response are not guaranteed. They are called after the response been constructed. They are not allowed to modify the request, and their values are ignored.
35. Please explain 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.