PYTHON
PYTHON
-----------------------------------------------------------------------------------
----------------------------
Q-3> WHAT IS PEP 8?
-----------------------------------------------------------------------------------
----------------------------
Q-4> WHAT DO YOU MEAN BY PYTHON LITERALS?
ANS:- Python literals can be defined as data which are given in a variable or
constant.
There are 6 types of literals in python:
String Literals:-
some text in single or double quote
Character Literals:-
single character inclosed in quotes
Numeric Literals:-
integer,float,complex
Boolean Literals:-
True,False
Special Literals:-
None
Literal Collections:-
list,tuple,dictionary,set
-----------------------------------------------------------------------------------
----------------------------
Q-5> EXPLAINS PYTHON FUNCTIONS?
ANS:- The python zip() function is used to transform multiple lists i.e
list1,list2,list3 into a single
list of tuples by taking the corresponding elements of lists that are passed
as parameters.
-----------------------------------------------------------------------------------
----------------------------
Q-7> WHICH ARE THE FILE RELATED LIBRARIES/MODULES IN PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-8> WHICH ARE THE DIFFRENT FILE PROCESSING MODES SUPPORTED BY PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-9> HOW MANY TYPES OF OPERATOR IN PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-10> WHAT IS OPERATOR IN PYTHON?
ANS:- An Operator is a particular symbol which is used on some values and produces
an output as result
for ex:- 3+4=7
here + and = are operators.
-----------------------------------------------------------------------------------
----------------------------
Q-11> HOW IS PYTHON INTREPRETED LANGUAGE?
-----------------------------------------------------------------------------------
-------------------------
Q-11> WHAT ARE DIFFERENCES BETWEEN LISTS AND TUPLES IN PYTHON?
ANS:- Lists and Tuples both are sequencial data types that can store a collection
of data in python.
The data stored in both sequences can have different data types.
Lists are represented with square brackets while tuples are represented with
paranthesis.
The key difference between the two is that lists are mutable data structure,
Tuple on the other hand are immutable.This means that lists can be
modified,but
Tuple remain constant and cannot be modified in any manner.
-----------------------------------------------------------------------------------
------------------------------
Q-12> WHAT IS __INIT__ IN PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-13> WHAT IS THE USE OF BREAK AND CONTINUE ?
ANS:- These two are keywords.Break and Continue statements can alter the flow of a
normal loop.
BREAK:-
The break statement terminates the loop.Control of the program flow
outside the body of the loop.
CONTINUE:-
The continue statement is used to skip the rest of the code inside a loop
for the current iteration
only.Loop does not terminate but continues on with the next iteration.
-----------------------------------------------------------------------------------
----------------------------
Q-14> WHAT IS SLICING IN PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-15> WHAT IS THE DIFFRENECE BETWEEN PYTHON ARRAY AND LIST ?
ANS:- Array in python can only contains elements of same data type i.e.,data type
of array should be
homogenous.
List in pyton can contain elements of different data types i.e., data type of
list can be heterogenous.
Arrays are fast while lists are slow.
-----------------------------------------------------------------------------------
----------------------------
Q-16> HOW ARRAY IS CREATED IN PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-17> HOW TO CREATE CONSTANT VARIABLE IN PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-18> WHAT IS LAMBDA IN PYTHON?
ANS:- Typecasting means changing one data type into another is known as
typecasting.
-----------------------------------------------------------------------------------
----------------------------
Q-20> WHAT ARE TUPLE IN PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-21> WHY PYTHON IS USED FOR FAST DEVELOPMENT CYCLE?
-----------------------------------------------------------------------------------
-----------------------------
Q-22> WHY PYTHON IS SLOWER THAN C AND C++?
ANS:- Since the code is not directly compiled and executed and an addtional layer
of the python virtual
machine is responsible for execution,Python code runs a little slow as
compared to conventional
language like C,C++,etc.
-----------------------------------------------------------------------------------
----------------------------
Q-23> WHAT IS A DYNAMICALLY TYPED LANGUAGE?
-----------------------------------------------------------------------------------
----------------------------
Q-24> WHAT IS STATICALLY TYPED AND DYNAMICALLY TYPED LANGUAGE?
-----------------------------------------------------------------------------------
----------------------------
Q-25> WHAT ARE THE TYPES OF SCOPE VARIBALE?
-----------------------------------------------------------------------------------
-----------------------------
Q-26> WHAT ARE THE BENEFITS OF USING PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-27> WHAT ARE DICTIONARY AND LIST COMPREHENSIONS?
ANS:- Dictionary and list comprehensions are just another concise way to define
dictionary and list.
EXAMPLE:-
X=[i for i in <collection>]
-----------------------------------------------------------------------------------
----------------------------
Q-28> WHAT ARE THE COMMON BUILT-IN DATA TYPES IN PYTHON?
1.NUMBER
integer,float,complex
2.LIST
3.TUPLE
4.STRING
5.SET
6.DICTIONARY
7.BOOLEAN
-----------------------------------------------------------------------------------
----------------------------
Q-29> WHAT IS THE DIFFERENCE BETWEEN .PY AND .PYC FILES?
ANS:- The .py files are the python source code files.while the pyc files contain
the bytecode of the python
files.The interpreter converts the source.py file to pyc.files.
-----------------------------------------------------------------------------------
---------------------------
Q-30> WHAT IS NAMESPACE IN PYTHON?
ANS:- A namespace is a naming system used to make sure that names are unique to
avoid nameing conflicts.
-----------------------------------------------------------------------------------
----------------------------
Q-31> HOW IS MEMORY MANAGED IN PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-32> WHAT ARE THE POSITIVE AND NEGATIVE INDICES?
ANS:-In the positive indices are applied the search beigns from left to the
right.In the case of negative
indices,the search begins from right to left.
for ex:-
Let the array list of size "n".In case of positive index the first index
is 0,then comes 1 and
until the last index is -1.
However in case of negative index the first index is -n,then -(n-1) until
the last index will be -1.
-----------------------------------------------------------------------------------
----------------------------
Q-33> WHAT ARE PYTHON MODULES? NAME SOME COMMON BUILT-IN-MODULE IN PYTHON?
ANS:-Python modules are files containing python code.This code can either be
funtions classes or variables.
A Python module is a .py file containing executable code.
Some of the commonly used built in modules are:-
1. OS
2.SYS
3.MATH
4.RANDOM
-----------------------------------------------------------------------------------
----------------------------
Q-34> WHAT ARE LOCAL VARIABLES AND GLOBAL VARIABLES IN PYTHON?
ANS:-GLOBAL VARIABLES:-
Variables declared outside a function or in global space are
called global variable.
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 varible is
present in the local space and not in the global space.
When you try to access the local varible outside the any
function,it will throw an error.
-----------------------------------------------------------------------------------
---------------------------
Q-35> IS INDENTATION REQUIRED IN PYTHON?
-----------------------------------------------------------------------------------
----------------------------
Q-36> HOW DO YOU MODIFY A STRING IN PYTHON?
s = list("Hello zorld")
print(s)
['H', 'e', 'l', 'l', 'o', ' ', 'z', 'o', 'r', 'l', 'd']
s[6] = 'W'
print(s)
['H',e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
m= "".join(s)
print(m)
Hello world
-----------------------------------------------------------------------------------
----------------------------
Q-37> WHAT IS THE DIFFERENCE BETWEEN LIST METHOD APPEND() AND EXTEND()?
ANS:-
APPEND:- Adds an element to a list.
EXTEND:- Concatenates the first list with another iterable (not necessary a
list,it can be any iterable).
x = [1, 2, 3]
x.append([4, 5])
print (x)
[1, 2, 3, [4, 5]]
x = [1, 2, 3]
x.extend([4, 5])
print (x)
[1, 2, 3, 4, 5]
x=[1,2,3]
x.entend((4,5))
print(x)
[1,2,3,4,5]
-----------------------------------------------------------------------------------
----------------------------
Q-38> WHY WE USE THE PASS STATEMENT IN PYTON?
ANS:-The pass statement is used as a placeholder for future code. When the pass
statement is executed,
nothing happens, Python has the syntactical requirement that code blocks
cannot be empty.
Otherwise,it will occur syntax error.
-----------------------------------------------------------------------------------
----------------------------
Q-39> WHAT IS CALLABLE?
-----------------------------------------------------------------------------------
----------------------------
Q-40> EXPLAIN SPLIT() AND JOIN() FUNCTION?
ANS:- You can use split() function to split a string to a list of strings based on
a delimiter.
You can use join() function to join a list of strings to give a single
string based on a delimiter.
-----------------------------------------------------------------------------------
----------------------------
Q-41> WHAT IS PANDAS IN PYTHON?
ANS:-Pandas is an open source python package that is mostly used for data
science/data analysis and
machine learning. It has a very rich set of data structure for data based
operations.
It provides two fantastic data structure:- series and dataframes.
DATAFRAMES:- it is mutable datatypes present in pandas library. It provides
support for heterogenous data.
PANDAS SERIES:- series is one dimensional pandas data structure present in
pandas library that supports
data of almost any types.
It supports multiple operations and is used for
single dimenshional data operation.
-----------------------------------------------------------------------------------
--------------------------------------
Q-42> HOW DO YOU ADD SINGLE-LINE AND MULTI-LINE COMMENTS IN PYTHON?
-----------------------------------------------------------------------------------
---------------------------------------
Q-43> WHAT IS THE EFFICIENT WAY TO ADD ELEMENT TO A TUPLE OR STRING?
-----------------------------------------------------------------------------------
-------------------------------------------
Q-44> WHAT IS DICTIONARY IN PYTHON?
ANS:- A Python dictionary is a collection of items with keys and values pair. It is
written in curly brackets.
They are optimized to retrieve value for known keys.
-----------------------------------------------------------------------------------
-------------------------------------------
Q-45> WHAT IS WITH STATEMENT USED FOR IN PYTHON?
ANS:-
-----------------------------------------------------------------------------------
-------------------------------------------
Q-46> WHAT IS A MAP() FUNCTION IN PYTHON?
ANS:- The map() function in python is used for applying a function on all elements
of a specified iterable.
* it consists of two parameters, function_name and iterable.
-----------------------------------------------------------------------------------
------------------------------------------
Q-47> WHAT IS DIFFERENCE BETWEEN NUMPY AND SCIPY?
ANS:- Numpy stands for Numerical python while Scipy stands for Scientific python.
* Numpy is the basic library for defining array and simple mathematical
problems.
* Scipy is used for more complex problems like numerical integration and
machine learning and so on.
-----------------------------------------------------------------------------------
-------------------------------------------
Q-48> HOW TO REMOVE SPACES FROM A STRING IN PYTHON?
ANS:- Spaces can be removed from a string in python by using strip() or replace()
functions.
* Strip() function is used to remove the leading and trailing white space
while the replace() fucnction
is used to remove all the white spaces in the string.
-----------------------------------------------------------------------------------
------------------------------------------------
Q-49> EXPLAIN THE FILE PROCESSING MODES THAT PYTHON SUPPORTS?
1. read-only mode(r)
2. write-only mode(w)
3. append-only mode(a)
4.r++ mode
5.w++ mode
6.a++ mode
-----------------------------------------------------------------------------------
-------------------------------------------------
Q-50> EXPLAIN ALL THE MODES?
ANS:-
-----------------------------------------------------------------------------------
-------------------------------------------------
Q-51>WHAT IS UNNITEST IN PYTHON?
ANS:- Unittest is a unit testing framework in python.
-----------------------------------------------------------------------------------
------------------------------------------------
Q-52> HOW DO YOU DELETE A FILE IN PYTHON?
-----------------------------------------------------------------------------------
------------------------------------------------
Q-53> HOW DO YOU CREATE AN EMPTY CLASS IN PYTHON?
ANS:- To create an empty class we can use the pass command after the definition of
the class object.
A pass is a statement in python that does nothing.
-----------------------------------------------------------------------------------
-------------------------------------------------
Q-54> WHAT ARE PYTHON DECORATORS?
ANS:- Decoratotrs are functions that take another functions as argument to modify
its behaviour without changing the function itself.
* These are useful when we want to dynamically increase the functionality of
a function without changing it.
-----------------------------------------------------------------------------------
------------------------------------------------------------
Q-55> WHAT DOES EARLY BINDING MEANS?
ANS:- Early binding is a popular concept in OOPS that is used for many purposes.
* Majorly, it is used to assign values during compile time to save a lot of
time during the execution of the entire project.
-----------------------------------------------------------------------------------
--------------------------------------------------------------