Python Is A Multiparadigm, General-purpose, Interpreted, High-level Programming Language. Python Allows Programmers To Use Different Programming Styles To Create Simple Or Complex Programs, Get Quicker Results And Write Code Almost As If Speaking In A Human Language.
1.What is Python? What are the benefits of using Python?
Python is a programming language with objects, modules, threads, exceptions and automatic memorymanagement. The benefits of pythons are that it is simple and easy, portable, extensible, build-in datastructure and it is an open source.
2.What is PEP 8?
PEP 8 is a coding convention, a set of recommendation, about how to write your Python code morereadable.
3.What is pickling and unpickling?
Pickle module accepts any Python object and converts it into a string representation and dumps it into afile by using dump function, this process is called pickling. While the process of retrieving original Pythonobjects from the stored string representation is called unpickling.
4.How Python is interpreted?
Python language is an interpreted language. Python program runs directly from the source code. It convertsthe source code that is written by the programmer into an intermediate language, which is again translatedinto machine language that has to be executed.
5.How memory is managed in Python?
Python memory is managed by Python private heap space. All Python objects and data structures are locatedin a private heap. The programmer does not have an access to this private heap and interpreter takes care ofthis Python private heap.
The allocation of Python heap space for Python objects is done by Python memory manager. The core APIgives 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 memoryand makes it available to the heap space.
6.What are the tools that help to find bugs or perform static analysis?
PyChecker is a static analysis tool that detects the bugs in Python source code and warns about the styleand complexity of the bug. Pylint is another tool that verifies whether the module meets the codingstandard.
7.What are Python decorators?
A Python decorator is a specific change that we make in Python syntax to alter functions easily.
8.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.gas a key for dictionaries.
9.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 areaccording to the functions; as a result you cannot change the value of the references. However, you canchange the objects if it is mutable.
10.What is Dict and List comprehensions are?
They are syntax constructions to ease the creation of a Dictionary or List based on existing iterable.
11.What are the built-in type does python provides?
There are mutable and Immutable types of Pythons built in types Mutable built-in types
12.What is namespace in Python?
In Python, every name introduced has a place where it lives and can be hooked for. This is known asnamespace. It is like a box where a variable name is mapped to the object placed. Whenever the variable issearched out, this box will be searched, to get corresponding object.
13.What is lambda in Python?
It is a single expression anonymous function often used as inline function.
14.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 thenreturn them at runtime.
15.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.
16.In Python what are iterators?
In Python, iterators are used to iterate a group of elements, containers like list.
17.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.
18.In Python what is slicing?
A mechanism to select a range of items from sequence types like list, tuple, strings etc. is known asslicing.
19.What are generators in Python?
The way of implementing iterators are known as generators. It is a normal function except that it yieldsexpression in the function.
20.What is docstring in Python?
A Python documentation string is known as docstring, it is a way of documenting Python
21.In Python what are iterators?
22.What is unittest in Python?
23.In Python what is slicing?
24.What are generators in Python?
25.What is docstring in Python?
A Python documentation string is known as docstring, it is a way of documenting Python functions,
26.How can you copy an object in Python?
To copy an object in Python, you can try copy.copy () or copy.deepcopy() for the general case. You cannotcopy all objects but most of them.
27.What is negative index in Python?
Python sequences can be index in positive and negative numbers. For positive index, 0 is the first index, 1is the second index and so forth. For negative index, (-1) is the last index and (-2) is the second last indexand so forth.
28.How you can 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 hexadecimalrepresentation, use the inbuilt function oct() or hex().
29.What is the difference between Xrange and range?
Xrange returns the xrange object while range returns the list, and uses the same memory and no matterwhat the range size is.
30.What is module and package in Python?
In Python, module is the way to structure program. Each Python program file is a module, which importsother modules like objects and attributes.
The folder of Python program is a package of modules. A package can have modules or subfolders.
31.Name some of the features of Python?
Following are some of the salient features of python ?
32.What is the purpose of PYTHONPATH environment variable?
PYTHONPATH - It has a role similar to PATH. This variable tells the Python interpreter where to locatethe module files imported into a program. It should include the Python source library directory and thedirectories containing Python source code. PYTHONPATH is sometimes preset by the Python installer.
33.What is the purpose of PYTHONSTARTUP environment variable?
PYTHONSTARTUP - It contains the path of an initialization file containing Python source code. It isexecuted every time you start the interpreter. It is named as .pythonrc.py in Unix and it contains commandsthat load utilities or modify PYTHONPATH.
34.What is the purpose of PYTHONSTARTUP environment variable?
35.What is the purpose of PYTHONCASEOK environment variable?
PYTHONCASEOK ? It is used in Windows to instruct Python to find the first case-insensitive match inan import statement. Set this variable to any value to activate it.
36.What is the purpose of PYTHONHOME environment variable?
PYTHONHOME ? It is an alternative module search path. It is usually embedded in the
PYTHONSTARTUP or PYTHONPATH directories to make switching module libraries easy.
37.Is python a case sensitive language?
Yes! Python is a case sensitive programming language.
38.What are the supported data types in Python?
Python has five standard data types ?
39.What is the output of print str if str = 'Hello World!'?
It will print complete string. Output would be Hello World!.
40.What is the output of print str[0] if str = 'Hello World!'?
It will print first character of the string. Output would be H.
41.What is the output of print str[2:5] if str = 'Hello World!'?
It will print characters starting from 3rd to 5th. Output would be llo.
42.What is the output of print str[2:] if str = 'Hello World!'?
It will print characters starting from 3rd character. Output would be llo World!.
43.What is the output of print str * 2 if str = 'Hello World!'?
It will print string two times. Output would be Hello World!Hello World!.
44.What is the output of print str + "TEST" if str = 'Hello World!'?
It will print concatenated string. Output would be Hello World!TEST.
45.What is the output of print list if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?
It will print complete list. Output would be ['abcd', 786, 2.23, 'john', 70.200000000000003].
46.What is the output of print list[0] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?
It will print first element of the list. Output would be abcd.
47.What is the output of print list[1:3] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?
It will print elements starting from 2nd till 3rd. Output would be [786, 2.23].
48.What is the output of print list[2:] if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]?
It will print elements starting from 3rd element. Output would be [2.23, 'john', 70.200000000000003].
49.What is the output of print tinylist * 2 if tinylist = [123, 'john']?
It will print list two times. Output would be [123, 'john', 123, 'john'].
50.What is the output of print list + tinylist * 2 if list = [ 'abcd', 786 , 2.23, 'john', 70.2 ] and tinylist = [123, 'john']?
It will print concatenated lists. Output would be ['abcd', 786, 2.23, 'john', 70.200000000000003, 123, 'john'].