[go: up one dir, main page]

0% found this document useful (0 votes)
8 views7 pages

Python QA

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Python QA

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1. What is Python.?

Python is a General-Purpose High-level Programming Language.


It is an Interpreted Programming Language
It supports Dynamic Memory Allocation
It is Very Powerful Object-Oriented Programming Language

2. Applications of Python.
Development
Testing
Data Engineer
Data Analyst
Data Science
Cloud
GUI
Front end dev
AI & ML etc

3. Identifiers.
It is a name given to a variable, function, class and other Objects.
Here we have some rules to be an identifier like
Identifier should starts with alphabet or _
Identifier can have number but should not start with number
It cannot have special characters except _
Keywords can not be used as identifier
Identifier can have any length but according to convention 79 characters.

4. Variable
It is place where we store the value and which can changeable
A= 56

5. Keyword
It is a pre-defined or reserved words which already have some special meaning.
In Python we have approximately 33 to 36 keywords
All keywords will be in orange color in python idle
Get keywords using from keyword import kwlist
rint(kwlist)

6. DataTypes:
It is a type the data which stored inside a variable
Data types are mainly classified into two types.
1. Individual / Single value Datatype:
Data which stores in a single memory block we call it as a single value or individual
datatype
a. Integer : It is number which does not have floating points & it can be pos or neg
num(default: 0)
b. Float: It is number which does have floating point & it can be pos or neg num
(default: 0.0)
c. Complex: It is combination of real and imaginary number, it is in the form of a+bj.
(default: 0j)
d. Boolean: It is used to check conditions. It has only 2 value which is True & False

2. Collection Datatype:
Collection of elements or Group of elements
Data which stored Layer by Layer.
All collections are enclosed with boundaries
To check length / number of elements present we can use len func

a. String: It is a collection of characters which boundaries are quotes, it supports


indexing and slicing & it is an immutable datatype which we can not modify the
original string. (default: ‘’)
b. List: It is a coll of homogeneous & Heterogeneous elements which boundaries are
square braces [……], It support indexing & slicing and it is mutable data which can
modify original. (default: [])
c. Tuple: It is a coll of homogeneous & Heterogeneous elements which boundaries are
Paranthesis (……), It support indexing & slicing and it is an immutable data which can
not modify original. (default ())
d. Set: It is a collection of immutable data which is mutable but not ordered datype.
(Default: set())
e. Dictionary: It is collection of Key value pair, key &value sep by collan (:) & It is
mutable. (default: {})

7. Operators:
Operators are special symbols which are used to perform particular task.
Here in python we have 7 types:
a. Arithmetic Operators:
Arithmetic operators are used to perform mathematical arithmetic operations
Arithmetic operators are divided into 7 types again.
i. Addition(+):
ii. Subtraction(-):
iii. Multiplication(*):
iv. True Division(/):
v. Floor Division (//):
vi. Modulus (%):
vii. Exponent (**) / power operator

b. Comparison Operator:
Comparison / Relational Operators are used to compare between two values
Always Comparison operators are returns Boolean values (True / False)
Here We are using some symbols like > < >= <= etc
Here two operands and one operators will be using
Syntax: operand-1 operator Operand-2
Here we have 6 types:
i. Greater than (>): returns True if operand-1 is greater than operand-2 else returns
False
ii. Greater than or equals (>=): returns True if operand-1 is greater than operand-2 or
operand-1 is equal to operand-2 else returns False
iii. Lesser than (<): returns True if operand-1 is lesser than operand-2 else returns False
iv. Lesser than or equals (<=): returns True if operand-1 is Lesser than operand-2 or
operand-1 is equal to operand-2 else returns False
v. Equals to (==): returns True if operand-1 is equals to operand-2 else it returns False.
vi. Not equals to (!=) : returns True if operand-1 is not equals to operand-2 else returns
False.

c. Logical Operators:
Logical Operators are used to perform Logical Operations and here we are utilizing
keywords called and, or & not
i. and: it is checking operand-1, if bool of op-1 is True than output will be op-2 else
op-1 will be ouput.
ii. or: it is checking operand-1, if bool of op-1 is False than output will be op-2 else
op-1 will be ouput.
iii. not: it is used for negation. It returns True If bool of operand is false else it
returns True
d. Membership Operators:
Membership operators are used to check whether given value is present in a collection
or not.
Here we are utilizing two keywords called in & not
i. in operator: it returns True if element is present in collection else return False.
Coll= [2, 3, 4, 6] → 3 in coll → True
ii. not in operator: it returns True if element is not present in collection else return
False.
Coll= [2, 3, 4, 6] → 7 not in coll → True

8. Control Statements

Control statements are those statements which are used to control the flow of execution of a
program by the decision we make in certain situations or conditions.

In control statements we have two types.

1. Conditional/ Decisional statement.


a. If
b. If else
c. If elif
d. Nested if

2. Looping Statement
a. While loop
b. For loop
9. Conditional Statements:

Conditional statements are those statements which will decide what to be done if the
condition is True and what to be done if condition is False.

a. if:

simple if statement is used to execute some set of statements only if the


condition is True.

Here to perform this we are utilizing a keyword called 'if'.

syntax:

if condition:

TSB

Working: In simple 'if' the True Statement Block (TSB) will be executed only if
the condition True, if the condition is False nothing will be executed.

b. if else:

if-else statement is used to execute some set of statements. If the condition is


True than the code which is present in True statement Block will be executed,

if condition is False than some other code whhich is present in FSB will be
executed.

syntax:

if condition:

____________

| |

| TSB |

|___________|

else:

____________

| |

| FSB |

|___________|

Working: In if-else, the condition will always be associated with 'if' keyword if ever
the condition is True than the code which is present in TSB will be executed.

if ever the condition id False than the code which is present in FSB will be executed.
The condition can be a True or False that means among TSB & FSB any one of the
statement block will be executed.

c. elif.

syntax:

if condition:

___________

| TSB |

|___________|

elif condition:

___________

| TSB |

|___________|

elif condition:

___________

| TSB |

|___________|

else:

___________

| FSB |

|___________|

Working:

First the condition is associated to the if statement will be check if the condition is
True than TSB of if will be executed, if condition is false than it will check condition
associated with elif and if it true than it executes TSB of first elif, else it will check
next condition associated with next elif, it check until it becomes any condition True.
if all the conditions are False than it executes FSB.

d. Nested if:

An if condition present inside another if condition is called nested if.

syntax:
if condition:

___________________

|if condition: |

| ___________ |

| | TSB | |

| |___________| |

|else: |

| ___________ |

| | FSB | |

| |___________| |

|___________________|

else:

___________

| FSB |

Working:

Firs it will check the condition associated with outer if, if the condition is True than it
enter into TSB and it will check the condition of nested if, if it is True than it will
execute the TSB of nested if. else it will check it is having elif or else... if cond of outer
if is False than it executes FSB of outer if.

Looping statements

Looping statements are used to repeat a set of statements for any number of times.

Here we have two types in loopings

1. While loop

2. for loop

1. While:-

While loop is a looping statement which is used for repeating some set of statements for a specified
number of times. while loop will always be associated with a condition, the statement block will be
executed until the given condition becomes False.

While loop will always be having looping variable which will be use in condition and the looping
variable value must be updated (either incrementation or decrementation) or else the while loop will

enter infinity looping.


syntax:

initialization = value #looping variable

while condition:

TSB

Updation

Working

step-1: Looping variable should always be declared before the while.

step-2:

First the while condition will check, if the condition True than the

TSB associated with the while loop will be executed after executes

TSB once the control again will go back to the while condition with

updated value of the looping variable again condition will check,

if the condition is True than the TSB will be executed again and this process will keep on happening
until the while condition will become False.

Note: If ever the looping is not updated in each & every iteration than the while condition will be
check for the same value for infinite number of times. Thus, it will enter infinite time loop.

You might also like