Question:- Give the output of this example: A[3] if A=[1,4,6,7,9,66,4,94].
Answer:- Since indexing starts from zero, an element present at 3rd index is 7. So, the output is 7.
Question:- What is type conversion in Python?
Answer:- Type conversion refers to the conversion of one data type iinto another. - int() - converts any data type into integer type - float() - converts any data type into float type - ord() - converts characters into integer - hex() - converts integers to hexadecimal - oct() - converts integer to octal - tuple() - This function is used to convert to a tuple. - set() - This function returns the type after converting to set. - list() - This function is used to convert any data type to a list type. - dict() - This function is used to convert a tuple of order (key,value) into a dictionary. - str() - Used to convert integer into a string. - complex(real,imag) - This functionconverts real numbers to complex(real,imag) number.
Question:- How to send an email in Python Language?
Answer:- To send an email, Python provides smtplib and email modules. Import these modules into the created mail script and send mail by authenticating a user. It has a method SMTP(smtp-server, port). It requires two parameters to establish SMTP connection.
Question:- What is the difference between Python Arrays and lists?
Answer:- Arrays and lists, in Python, have the same way of storing data. But, arrays can hold only a single data type elements whereas lists can hold any data type elements.
Question:- What is lambda function in Python?
Answer:- The anonymous function in python is a function that is defined without a name. The normal functions are defined using a keyword "def", whereas, the anonymous functions are defined using the lambda function. The anonymous functions are also called as lambda functions.
Question:- Why do lambda forms in Python not have the statements?
Answer:- Lambda forms in Python does not have the statement because it is used to make the new function object and return them in runtime.
Question:- What are functions in Python?
Answer:- A function is a block of code which is executed only when it is called. To define a Python function, the def keyword is used.
Question:- What is __init__?
Answer:- The __init__ is a method or constructor in Python. This method is automatically called to allocate memory when a new object/ instance of a class is created. All classes have the __init__ method.
Question:- What is PYTHONPATH?
Answer:- PYTHONPATH is an environment variable which is used when a module is imported. Whenever a module is imported, PYTHONPATH is also looked up to check for the presence of the imported modules in various directories. The interpreter uses it to determine which module to load.
Question:- What are python modules? Name some commonly used built-in modules in Python?
Answer:- Python modules are files containing Python code. This code can either be functions classes or variables. A Python module is a .py file containing executable code. Some of the commonly used built-in modules are: - os - sys - math - random - data time - JSON
Question:- What is the difference between range & xrange?
Answer:- For the most part, xrange and range are the exact same in terms of functionality. They both provide a way to generate a list of integers for you to use, however you please. The only difference is that range returns a Python list object and x range returns an xrange object. This means that xrange doesnt actually generate a static list at run-time like range does. It creates the values as you need them with a special technique called yielding. This technique is used with a type of object known as generators. That means that if you have a really gigantic range youd like to generate a list for, say one billion, xrange is the function to use. This is especially true if you have a really memory sensitive system such as a cell phone that you are working with, as range will use as much memory as it can to create your array of integers, which can result in a Memory Error and crash your program. Its a memory hungry beast.
Question:- What advantages do NumPy arrays offer over (nested) Python lists?
Answer:- - Pythons lists are efficient general-purpose containers. They support (fairly) efficient insertion, deletion, appending, and concatenation, and Pythons list comprehensions make them easy to construct and manipulate. - They have certain limitations: they dont support "vectorized" operations like elementwise 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. - NumPy is not just more efficient; it is also more convenient. We get a lot of vector and matrix operations for free, which sometimes allow one to avoid unnecessary work. And they are also efficiently implemented. - NumPy array is faster and we get a lot built in with NumPy, FFTs, convolutions, fast searching, basic statistics, linear algebra, histograms, etc.
Question:- Mention what the Django templates consist of.
Answer:- The template is a simple text file. It can create any text-based format like XML, CSV, HTML, etc. A template contains variables that get replaced with values when the template is evaluated and tags (% tag %) that control the logic of the template.
Question:- Explain the use of session in Django framework?
Answer:- Django provides a session that lets the user store and retrieve data on a per-site-visitor basis. Django abstracts the process of sending and receiving cookies, by placing a session ID cookie on the client side, and storing all the related data on the server side.
