python

[vc_row full_width=”stretch_row” css=”.vc_custom_1559286923229{background-color: #f6f6f7 !important;}”][vc_column width=”1/2″][vc_tta_accordion color=”peacoc” active_section=”1″][vc_tta_section title=”What is Python? What are the benefits of using Python?” tab_id=”1561380734745-33beb91d-8440″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is PEP 8?” tab_id=”1561380734815-9d245277-5c3f”][vc_column_text]

PEP 8 is a coding convention, a set of recommendation, about how to write your Python code more readable.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is pickling and unpickling?” tab_id=”1561380734884-3fec4bce-3e63″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Can the application be rejected?” tab_id=”1561380734951-d04bd78b-9539″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”How memory is managed in Python?” tab_id=”1561380735020-bdbaf2ce-1209″][vc_column_text]

  • 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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are the tools that help to find bugs or perform static analysis?” tab_id=”1561380735095-eafb0540-fd74″][vc_column_text]

  • PyChecker is a static analysis tool that detects the bugs in Python source code and warns about the style and complexity of the bug. Pylint is another tool that verifies whether the module meets the coding standard.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are Python decorators?” tab_id=”1561380735167-e519aec9-3c8f”][vc_column_text]A Python decorator is a specific change that we make in Python syntax to alter functions easily.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the difference between list and tuple?” tab_id=”1561380735235-b63eea38-9669″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”How are arguments passed by value or by reference?” tab_id=”1561380735308-00f8844c-9591″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is Dict and List comprehensions are?” tab_id=”1561380735385-954e2deb-9791″][vc_column_text]

They are syntax constructions to ease the creation of a Dictionary or List based on existing iterable.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are the built-in type does python provides?” tab_id=”1561380735462-a6d5c034-d69e”][vc_column_text]

There are mutable and Immutable types of Pythons built in types Mutable built-in types

  • List
  • Sets
  • Dictionaries

Immutable built-in types

  • Strings
  • Tuples
  • Numbers

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is namespace in Python?” tab_id=”1561380735527-735ca0be-1add”][vc_column_text]

In Python, every name introduced has a place where it lives and can be hooked for. This is known as namespace. It is like a box where a variable name is mapped to the object placed. Whenever the variable is searched out, this box will be searched, to get corresponding object.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is lambda in Python?” tab_id=”1561380735600-07d96f71-496f”][vc_column_text]

It is a single expression anonymous function often used as inline function.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Why lambda forms in python does not have statements?” tab_id=”1561380735670-09ca241c-06e3″][vc_column_text]

A lambda form in python does not have statements as it is used to make new function object and then return them at runtime.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is pass in Python?” tab_id=”1561380735750-1ae05942-6b99″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”In Python what are iterators?” tab_id=”1561380735839-d05e9958-7084″][vc_column_text]

In Python, iterators are used to iterate a group of elements, containers like list.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is unittest in Python?” tab_id=”1561380735919-ee10b1e0-0a51″][vc_column_text]

In Python, iterators are used to iterate a group of elements, containers like list.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”In Python what is slicing?” tab_id=”1561380735999-498445af-7ecb”][vc_column_text]

In Python, iterators are used to iterate a group of elements, containers like list.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are generators in Python?” tab_id=”1561380736077-237915a8-1925″][vc_column_text]

The way of implementing iterators are known as generators. It is a normal function except that it yields expression in the function.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain how can you generate random numbers in Python?” tab_id=”1561380736157-ff898b51-ebca”][vc_column_text]

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)

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is docstring in Python?” tab_id=”1561380736237-8ace1ff9-3b99″][vc_column_text]

A Python documentation string is known as docstring, it is a way of documenting Python functions, modules and classes.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”How can you copy an object in Python?” tab_id=”1561380736325-8757d492-d503″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is negative index in Python?” tab_id=”1561380736407-c3ce72b9-6f15″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”How you can convert a number to a string?” tab_id=”1561380736498-db3a9d9d-c257″][vc_column_text]

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().

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the difference between Xrange and range?” tab_id=”1561380736591-c228374d-b090″][vc_column_text]

Xrange returns the xrange object while range returns the list, and uses the same memory and no matter what the range size is.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is module and package in Python?” tab_id=”1561380736682-4f3a3b5d-f446″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Mention what are the rules for local and global variables in Python?” tab_id=”1561380736775-e5ebcf7d-1ee1″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Mention what are the rules for local and global variables in Python?” tab_id=”1561380736869-219b35fa-c28c”][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”How can you share global variables across modules?” tab_id=”1561380736967-4aa3007b-0311″][vc_column_text]

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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain how can you make a Python Script executable on Unix?” tab_id=”1561380737061-2f097ce2-3850″][vc_column_text]

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)

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain how to delete a file in Python?” tab_id=”1561380737164-d70b8e01-ad82″][vc_column_text]

By using a command os.remove (filename) or os.unlink(filename)

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is a lambda function?” tab_id=”1583946187152-c397204f-8451″][vc_column_text] An anonymous function is known as a lambda function. This function can have any number of parameters but, can have just one statement.

Example:

1
2
a = lambda x,y : x+y
print(a(5, 6))

Output: 11[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is self in Python?” tab_id=”1583946777192-491d4484-40d4″][vc_column_text]Self is an instance or an object of a class. In Python, this is explicitly included as the first parameter. However, this is not the case in Java where it’s optional.  It helps to 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.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How does break, continue and pass work?” tab_id=”1583946778369-1591719b-2590″][vc_column_text]

Break Allows loop termination when some condition is met and the control is transferred to the next statement.
Continue Allows skipping some part of a loop when some specific condition is met and the control is transferred to the beginning of the loop
Pass Used when you need some block of code syntactically, but you want to skip its execution. This is basically a null operation. Nothing happens when this is executed.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What does `{`::-1} do?” tab_id=”1583946779381-cba19927-15a2″][vc_column_text]

[::-1] is used to reverse the order of an array or a sequence.
For example:
1
2
3
import array as arr
My_Array=arr.array('i',[1,2,3,4,5])
My_Array[::-1]

Output: array(‘i’, [5, 4, 3, 2, 1])

[::-1] reprints a reversed copy of ordered data structures such as an array or a list. the original array or list remains unchanged.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”How can you randomize the items of a list in place in Python?” tab_id=”1583946780689-078eca66-78a7″][vc_column_text]Consider the example shown below:

1
2
3
4
from random import shuffle
x = ['Keep', 'The', 'Blue', 'Flag', 'Flying', 'High']
shuffle(x)
print(x)

The output of the following code is as below.

['Flying', 'Keep', 'Blue', 'High', 'The', 'Flag']

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are python iterators?” tab_id=”1583946790293-8b8bef80-2e8e”][vc_column_text]Iterators are objects which can be traversed though or iterated upon.[/vc_column_text][/vc_tta_section][vc_tta_section title=” How can you generate random numbers in Python?” tab_id=”1583947183158-96fb3aed-e6ff”][vc_column_text]Random module is the standard module that is used to generate a random number. The method is defined as:

1
2
import random
random.random

The statement random.random() method return the floating point number that is in the range of [0, 1). The function generates random float numbers. The methods that are used with the random class are the bound methods of the hidden instances. The instances of the Random can be done to show the multi-threading programs that creates a different instance of individual threads. The other random generators that are used in this are:

  1. randrange(a, b): it chooses an integer and define the range in-between [a, b). It returns the elements by selecting it randomly from the range that is specified. It doesn’t build a range object.
  2. uniform(a, b): it chooses a floating point number that is defined in the range of [a,b).Iyt returns the floating point number
  3. normalvariate(mean, sdev): it is used for the normal distribution where the mu is a mean and the sdev is a sigma that is used for standard deviation.
  4. The Random class that is used and instantiated creates an independent multiple random number generators.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the difference between range & xrange?” tab_id=”1583947185550-dd52aae7-0286″][vc_column_text]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 doesn’t 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 you’d 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. It’s a memory hungry beast.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How do you write comments in python?” tab_id=”1583947186864-3919695f-26ce”][vc_column_text]Comments in Python start with a # character. However, alternatively at times, commenting is done using docstrings(strings enclosed within triple quotes).

Example:

#Comments in Python start like this
print("Comments in Python start with a #")

Output:  Comments in Python start with a #[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is pickling and unpickling?” tab_id=”1583947187734-0bd48ecb-9f21″][vc_column_text]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.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How will you capitalize the first letter of string?” tab_id=”1583947188690-d7c25afe-fc05″][vc_column_text]In Python, the capitalize() method capitalizes the first letter of a string. If the string already consists of a capital letter at the beginning, then, it returns the original string.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How will you convert a string to all lowercase?” tab_id=”1583947189557-3514f655-ac02″][vc_column_text]To convert a string to lowercase, lower() function can be used.

Example:

1
2
stg='ABCD'
print(stg.lower())

Output: abcd[/vc_column_text][/vc_tta_section][/vc_tta_accordion][/vc_column][vc_column width=”1/2″][vc_tta_accordion color=”peacoc” active_section=”1″][vc_tta_section title=”Mention what are the rules for local and global variables in Python?” tab_id=”1559286383409-ab730398-6c03″][vc_column_text]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.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How can you share global variables across modules?” tab_id=”1559286383419-ca1e4f09-b484″][vc_column_text]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.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain how can you make a Python Script executable on Unix?” tab_id=”1559286461195-8472c861-81ff”][vc_column_text]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)

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain how to delete a file in Python?” tab_id=”1559286499169-f2685778-8e5b”][vc_column_text]By using a command os.remove (filename) or os.unlink(filename)[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain how can you generate random numbers in Python?” tab_id=”1559286522681-3bf94e12-e7b7″][vc_column_text]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)[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain how can you access a module written in Python from C?” tab_id=”1561379780152-91d604cd-8192″][vc_column_text]

  • You can access a module written in Python from C by following method,Module = =PyImport_ImportModule(“<modulename>”);

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Mention the use of // operator in Python?” tab_id=”1561379805690-6c207bf9-3703″][vc_column_text]It is a Floor Divisionoperator , which is used for dividing two operands with the result as quotient showing only digits before the decimal point. For instance, 10//5 = 2 and 10.0//5.0 = 2.0.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Mention five benefits of using Python?” tab_id=”1561379854070-e3d92139-3c5f”][vc_column_text]

  • 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

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Mention the use of the split function in Python?” tab_id=”1561379918105-46fb5eec-1966″][vc_column_text]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.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain what is Flask & its benefits?” tab_id=”1561379970480-b7950869-d0ed”][vc_column_text]Flask is a web micro framework for Python based on “Werkzeug, Jinja 2 and good intentions” BSD licensed. Werkzeug and jingja are two of its dependencies.

Flask is part of the micro-framework. Which means it will have little to no dependencies on external libraries. It makes the framework light while there is little dependency to update and less security bugs.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Mention what is the difference between Django, Pyramid, and Flask?” tab_id=”1561379998918-34c218f0-fa76″][vc_column_text]Flask is a “microframework” primarily build for a small application with simpler requirements. In flask, you have to use external libraries. Flask is ready to use.

Pyramid are build for larger applications. It provides flexibility and lets the developer use the right tools for their project. The developer can choose the database, URL structure, templating style and more. Pyramid is heavy configurable.

Like Pyramid, Django can also used for larger applications. It includes an ORM.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Mention what is Flask-WTF and what are their features?” tab_id=”1561380048168-645262ed-eb94″][vc_column_text]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

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain what is the common way for the Flask script to work?” tab_id=”1561380084799-7406e3a2-79da”][vc_column_text]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

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain how you can access sessions in Flask?” tab_id=”1561380110946-8d0ace25-a3f1″][vc_column_text]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.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Is Flask an MVC model and if yes give an example showing MVC pattern for your application?” tab_id=”1561380132231-bebe187b-a4b5″][vc_column_text]Basically, Flask is a minimalistic framework which behaves same as MVC framework. So MVC is a perfect fit for Flask, and the pattern for MVC we will consider for the following example

from flask import Flaskapp = Flask(_name_)

@app.route(“/”)

Def hello():

return “Hello World”

app.run(debug = True)

In this code your,

  • Configuration part will be

from flask import Flask

app = Flask(_name_)

  • View part will be

@app.route(“/”)

Def hello():

return “Hello World”

  • While you model or main part will be

app.run(debug = True)

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain database connection in Python Flask?” tab_id=”1561380170069-4c1eb949-b773″][vc_column_text]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.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”You are having multiple Memcache servers running Python, in which one of the memcacher server fails, and it has your data, will it ever try to get key data from that one failed server?” tab_id=”1561380195532-71adcf1c-e58d”][vc_column_text]The data in the failed server won’t get removed, but there is a provision for auto-failure, which you can configure for multiple nodes. Fail-over can be triggered during any kind of socket or Memcached server level errors and not during normal client errors like adding an existing key, etc.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain how you can minimize the Memcached server outages in your Python Development?” tab_id=”1561380234653-d23ea206-cefb”][vc_column_text]

  • 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

 

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain what is Dogpile effect? How can you prevent this effect?” tab_id=”1561380255337-b60079cc-391b”][vc_column_text]Dogpile effect is referred to the event when cache expires, and websites are hit by the multiple requests made by the client at the same time. This effect can be prevented by using semaphore lock. In this system when value expires, first process acquires the lock and starts generating new value.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Explain how Memcached should not be used in your Python project?” tab_id=”1561380274827-dcb9bbfd-5d8d”][vc_column_text]

  • Memcached common misuse is to use it as a data store, and not as a cache
  • Never use Memcached as the only source of the information you need to run your application. Data should always be available through another source as well
  • Memcached is just a key or value store and cannot perform query over the data or iterate over the contents to extract information
  • Memcached does not offer any form of security either in encryption or authentication

[/vc_column_text][/vc_tta_section][vc_tta_section title=” What is the difference between list and tuples in Python?” tab_id=”1583946174106-d71a23ae-ce90″][vc_column_text]

LIST TUPLES
Lists are mutable i.e they can be edited. Tuples are immutable (tuples are lists which can’t be edited).
Lists are slower than tuples. Tuples are faster than list.
Syntax: list_1 = [10, ‘Chelsea’, 20] Syntax: tup_1 = (10, ‘Chelsea’ , 20)

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are the key features of Python?” tab_id=”1583946175213-5e289665-1617″][vc_column_text]

  • 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 publicprivate).
  • 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 modeling, big data applications and many more. It’s also often used as “glue” code to get other languages and components to play nice.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What type of language is python? Programming or scripting?” tab_id=”1583946178297-05a93be2-a208″][vc_column_text]Python is capable of scripting, but in general sense, it is considered as a general-purpose programming language. To know more about Scripting, you can refer to the Python Scripting Tutorial.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How is Python an interpreted language?” tab_id=”1583946179077-d066b739-ed7b”][vc_column_text] An interpreted language is any programming language which is not in machine level code before runtime. Therefore, Python is an interpreted language.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is pep 8?” tab_id=”1583946179626-85664862-6180″][vc_column_text]PEP stands for Python Enhancement Proposal.It is a set of rules that specify how to format Python code for maximum readability.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How is memory managed in Python?” tab_id=”1583946180559-875603a0-dc30″][vc_column_text]

  1. Memory management in python is managed by Python private heap space. All Python objects and data structures are located in a private heap. The programmer does not have access to this private heap. The python interpreter takes care of this instead.
  2. The allocation of heap space for Python objects is done by Python’s memory manager. The core API gives access to some tools for the programmer to code.
  3. Python also has an inbuilt garbage collector, which recycles all the unused memory and so that it can be made available to the heap space.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is namespace in Python?” tab_id=”1583946181126-d752e019-d4fe”][vc_column_text] A namespace is a naming system used to make sure that names are unique to avoid naming conflicts.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is PYTHONPATH?” tab_id=”1583946181781-83fcf937-7100″][vc_column_text]It 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.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are python modules? Name some commonly used built-in modules in Python?” tab_id=”1583946182968-4a649c65-f86f”][vc_column_text] 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

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are local variables and global variables in Python? ” tab_id=”1583946183627-42b1f505-45b9″][vc_column_text]Global Variables:

Variables declared outside a function or in global space are called global variables. These variables can be accessed by any function in the program.

Local Variables:

Any variable declared inside a function is known as a local variable. This variable is present in the local space and not in the global space.

Example:

1
2
3
4
5
6
a=2
def add():
b=3
c=a+b
print(c)
add()

Output: 5

When you try to access the local variable outside the function add(), it will throw an error.[/vc_column_text][/vc_tta_section][vc_tta_section title=”Is python case sensitive?” tab_id=”1583946184264-d8ba488a-ac3c”][vc_column_text]Yes. Python is a case sensitive language.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is type conversion in Python?” tab_id=”1583946185344-27f306d7-adf6″][vc_column_text] 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.[/vc_column_text][/vc_tta_section][vc_tta_section title=”How to install Python on Windows and set path variable?” tab_id=”1583946188666-243b73f8-13a1″][vc_column_text]To install Python on Windows, follow the below steps:

  • Install python from this link: https://www.python.org/downloads/
  • After this, install it on your PC. Look for the location where PYTHON has been installed on your PC using the following command on your command prompt: cmd python.
  • Then go to advanced system settings and add a new variable and name it as PYTHON_NAME and paste the copied path.
  • Look for the path variable, select its value and select ‘edit’.
  • Add a semicolon towards the end of the value if it’s not present and then type %PYTHON_HOME%

[/vc_column_text][/vc_tta_section][vc_tta_section title=” Is indentation required in python?” tab_id=”1583946782823-d0e9edac-80d1″][vc_column_text] Indentation is necessary for Python. It specifies a block of code. All code within loops, classes, functions, etc is specified within an indented block. It is usually done using four space characters. If your code is not indented necessarily, it will not execute accurately and will throw errors as well.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the difference between Python Arrays and lists?” tab_id=”1583946785595-380fdee6-2ec7″][vc_column_text]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.

Example:

1
2
3
4
5
import array as arr
My_Array=arr.array('i',[1,2,3,4])
My_list=[1,'abc',1.20]
print(My_Array)
print(My_list)

Output:

array(‘i’, [1, 2, 3, 4]) [1, ‘abc’, 1.2][/vc_column_text][/vc_tta_section][vc_tta_section title=”What are functions in Python?” tab_id=”1583946787457-fca7c9b8-eada”][vc_column_text]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.

Example:

1
2
3
def Newfunc():
print("Hi, Welcome to Edureka")
Newfunc(); #calling the function

Output: Hi, Welcome to Edureka[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is __init__?” tab_id=”1583946788747-1a14b02a-66e6″][vc_column_text] __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.

Here is an example of how to use it.

1
2
3
4
5
6
7
8
9
10
11
class Employee:
def __init__(self, name, age,salary):
self.name = name
self.age = age
self.salary = 20000
E1 = Employee("XYZ", 23, 20000)
# E1 is the instance of class Employee.
#__init__ allocates memory for E1.
print(E1.name)
print(E1.age)
print(E1.salary)

Output:

XYZ

23

20000[/vc_column_text][/vc_tta_section][vc_tta_section title=”How to comment multiple lines in python?” tab_id=”1583947016646-85412d38-e37a”][vc_column_text]Multi-line comments appear in more than one line. All the lines to be commented are to be prefixed by a #. You can also a very good shortcut method to comment multiple lines. All you need to do is hold the ctrl key and left click in every place wherever you want to include a # character and type a # just once. This will comment all the lines where you introduced your cursor.[/vc_column_text][/vc_tta_section][vc_tta_section title=”What are docstrings in Python?” tab_id=”1583947192897-03b9069f-9e65″][vc_column_text] Docstrings are not actually comments, but, they are documentation strings. These docstrings are within triple quotes. They are not assigned to any variable and therefore, at times, serve the purpose of comments as well.

Example:

1
2
3
4
5
6
7
8
"""
Using docstring as a comment.
This code divides 2 numbers
"""
x=8
y=4
z=x/y
print(z)

Output: 2.0[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the purpose of is, not and in operators?” tab_id=”1583947194128-ff068f2d-16c3″][vc_column_text] Operators are special functions. They take one or more values and produce a corresponding result.

is: returns true when 2 operands are true  (Example: “a” is ‘a’)

not: returns the inverse of the boolean value

in: checks if some element is present in some sequence[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is the usage of help() and dir() function in Python?” tab_id=”1583947194959-ccc86faa-1525″][vc_column_text]Help() and dir() both functions are accessible from the Python interpreter and used for viewing a consolidated dump of built-in functions.

  1. Help() function: The help() function is used to display the documentation string and also facilitates you to see the help related to modules, keywords, attributes, etc.
  2. Dir() function: The dir() function is used to display the defined symbols.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”Whenever Python exits, why isn’t all the memory de-allocated?” tab_id=”1583947195815-fe85a114-d468″][vc_column_text]

  1. 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.
  2. It is impossible to de-allocate those portions of memory that are reserved by the C library.
  3. On exit, because of having its own efficient clean up mechanism, Python would try to de-allocate/destroy every other object.

[/vc_column_text][/vc_tta_section][vc_tta_section title=”What is a dictionary in Python?” tab_id=”1583947197208-751131ce-bc48″][vc_column_text]The built-in datatypes in Python is called dictionary. It defines one-to-one relationship between keys and values. Dictionaries contain pair of keys and their corresponding values. Dictionaries are indexed by keys.

Let’s take an example:

The following example contains some keys. Country, Capital & PM. Their corresponding values are India, Delhi and Modi respectively.

1
dict={'Country':'India','Capital':'Delhi','PM':'Modi'}
1
print dict[Country]
India
1
print dict[Capital]
Delhi
1
print dict[PM]
Modi

[/vc_column_text][/vc_tta_section][/vc_tta_accordion][/vc_column][/vc_row][vc_row full_width=”stretch_row_content_no_spaces” css=”.vc_custom_1561617363245{background-image: url(https://www.coursesit.us/wp-content/uploads/2019/06/best-python-training-institute-class-course-in-indore.png?id=7110) !important;background-position: center !important;background-repeat: no-repeat !important;background-size: cover !important;}”][vc_column][vc_empty_space height=”500px”][/vc_column][/vc_row]

WhatsApp us