Mostly Asked FAQ's Python
Mostly Asked FAQ's Python
Ans. Both Interpreter and complier works in the same way, they acts as translators.
Compiler conerts the high level language to low level language i.e machine language
or assembly language. low level language means (0's, 1's).
Interpreter converts the high level language to intermediate language with many
steps.It contains pre-compiled code and source code.
Ans. In other languages, we have to declare the type of data. But, python itself
declares the varibles assingned and describes the data types.
5. fundamental datatypes
Ans. These are also called keywords,which means they are predefined meaning and
syntax in the language.
ex : and, except, lambda, with, as yeild, try, except,finally.
Ans. collection data types are otherwise called as data structures/containers which
stores large number of data in a variable.
There are four types of data structures.
1. List
2. Tuple
3. Dict
4. Set
Tuple performs faster operations than list because of its static characterstics
also contain less build in functions and low utilization of memory.
Syntax :
Ans.del removes an element(s) by index. At the same time, pop() removes it by index
and also returns the value.
Ans. Splits the string at the specified separator, and returns a list,Joins the
elements of an iterable to the end of the string
Ans. These are part of control flow statements and also called as transfer
statements.
Break : break terminates the entire loop if the conditon is true and moves to next
step.
Continue : countine moves to next iteration when the condition is true and doesnt
terminates the loop.
pass : pass passes the input and helps to run program smoothly.
22. Recursion.
Ans. map and filter are two built-in functions in Python that are commonly used
with lambda functions to process and manipulate data in iterable objects, such as
lists or tuples.
==> map function applies a given function to each elements of an iteration and
returns an iterator that contain results.
Syntax for map:
--> map(lambda function, items)
==> Filter funtion filters and create a list of elements for which condition become
True.
Syntax for Filter:
--> filter(function, items)
CLASS:-
=> Class is a logical entity that create template/blueprint like structure.
=> Class is a combination of Attributes and its functions.
=> Class can be defines as the collection of Objects.
EX:- if we have a class called Employee
than their attribute and methods are mailid, Name, Age, Salary, etc.
Create class:
-> Class is denoted using 'class'
Syntax:- Class classname:
OBJECT:-
=> Everything is an object in the python and it has its own address.
or()
=> Object is the entity that has state and behavios.
=> Object is the collection of variables and functions.
EX:-List,Dict,String (everything is an object)
Concepts in OOPS:
1). Encapsulation:-
*It is defined as Binding of Attributes and methonds of an object in a class.
*Mainly used to protect the data.
3types of access specifiers:
1). public
2).private __
3) protect _
2). Polymorphism:-
*In the name itself Poly = Many and Morphism = changes
*it is defines as Objects behave diffently as pr the need.
@ Using of the same function name but with different behaviors.
example:- animals and speak.
Here, animal is a class and the speak has different way like dog can speak as
barking
so here the accrion is speak is performed in different ways but the class is same.
3). Abstraction :-
* Used to hide the internal functionality of the function from the user.
* User only interact with the basic implementation of the function but the
inner waor is hidden
=> The process of hiding the certain details and showing only the essential
information to the user.
example:- Using TV remote to increase the volume.
here we only know how to press the +button to increase the volume but we do not
know hpw actually uit works inside.
4). Inheritance :-
* Receiving attributes and methods from one class to another class.
=> The class whose attributes and methods are inherited is called as 'PARENT
class (or)BASE class.'
=> The class that recieve attributes and methods from the base class is called as
'CHILD class (or) DERIVED class'
Types of inheritance:-
---------------------