How does Python Flask handle database requests?
Flask supports a database-powered application (RDBS). Such a system requires creating a schema, which needs piping the schema.sql file into the sqlite3 command. Python developers need to install the sqlite3 command to create or initiate the database in Flask.
Flask allows to request for a 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 a situation when an exception is raised and responses are not guaranteed. They are called after the response has been constructed. They are not allowed to modify the request, and their values are ignored.
What is self in Python programming language
Self is an object or an instance of a class. This is explicitly included as the first parameter in Python. On the other hand, in Java it is optional. It helps differentiate between the methods and attributes of a class with local variables.
The self variable in the init method refers to the newly created object, while in other methods, it refers to the object whose method was called
What advantages do NumPy arrays offer over (nested) Python lists?
Nested Lists :
- Python lists are efficient general-purpose containers that support efficient operations like insertion,appending,deletion and concatenation.
- The limitations of lists are that they don’t support “vectorized” operations like element wise addition and multiplication, and the fact that they can contain objects of differing types mean that Python must store type information for every element, and must execute type dispatching code when operating on each element.
Whenever Python exits, why isnt all the memory de-allocated?
Whenever Python exits, especially those Python modules which are having circular references to other objects or the objects that are referenced from the global namespaces are not always de-allocated or freed.
It is not possible to de-allocate those portions of memory that are reserved by the C library.
On exit, because of having its own efficient clean up mechanism, Python would try to de-allocate every object.
What do file-related modules in Python do? Can you name some file-related modules in Python?
Python comes with some file-related modules that have functions to manipulate text files and binary files in a file system. These modules can be used to create text or binary files, update their content, copy, delete, and more.
Some file-related modules are os, os.path, and shutil.os. The os.path module has functions to access the file system, while the shutil.os module can be used to copy or delete files.
Is indentation required in Python?
Indentation in Python is compulsory and is part of its syntax.
All programming languages have some way of defining the scope and extent of the block of codes. In Python, it is indentation. Indentation provides better readability to the code, which is probably why Python has made it compulsory.
What is type conversion in Python
Python provides you with a much needed functionality of converting one form of data type into the needed one and this is known as type conversion.
Type Conversion is classified into types:
1.Implicit Type Conversion: In this form of Type conversion python interpreter helps in automatically converting the data type into another data type without any User involvement.
2.Explicit Type Conversion: In this form of Type conversion the data type inn changed into a required type by the user.
What are local variables and global variables in Python?
Local variable : Any variable declared inside a function is known as Local variable and it’s accessibility remains inside that function only.
Global Variable : Any variable declared outside the function is known as Global variable and it can be easily accessible by any function present throughout the program.
What are the common built-in data types in Python?
Python supports the below-mentioned built-in data types:
Immutable data types:
- Number
- String
- Tuple
Mutable data types:
- List
- Dictionary
- set
What is __init__ in Python explain its significance
Equivalent to constructors in OOP terminology, __init__ is a reserved method in Python classes. The __init__ method is called automatically whenever a new object is initiated. This method allocates memory to the new object as soon as it is created. This method can also be used to initialize variables.