PythonQ
PythonQ
Python is a dynamic language because you don’t have to declare data type while
assigning a value.
Features of Python
Value: These are the data stored inside the variable (placeholder).
a = 10
a = ’Hello’
Identifier and Keywords
Identifiers: These are some rules and regulations which are followed to name a variable.
Rule 1: It can be alphabet, alphanumeric but it should not start with numbers.
a = 10
a1 = 10
1a = 10
@ = 10
# = 10
! = 10
_ = 10
ab = 10
a b = 10
Keywords
These are some predefined words having some specific tasks to do.
Example: ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class',
'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is',
'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
Data Types
Datatypes are used to specify the type of data stored inside a variable
Single valued data type: These are the data which are stored individually inside a
variable in the form of integer, float, complex, Boolean.
Integer: The numbers which can be represented on a number line in the form of
negative, positive and zero.
a 0x11
0x11 10
P Y T H O N
0 1 2 3 4 5
Slicing: It’s a phenomenon of extracting the sub data from a given data using indexing.
1. Individual Slicing
2. Group Slicing
Syntax: var[index_position]
a = ‘python’
a[2] = t
[start:stop:step]
List is mutable in nature where we can add data, insert data or remove data from the
list.
1. append() – It is a function which is used to add data to the last of the collection.
syntax: var.append(value)
2. insert() – It is an inbuilt function which is used to add data as per user index
position.
syntax: var.insert( index position, value)
1. Immutable in nature where we can access the data but can’t modify it.
2. In python, tuple is the most secure data type which has security.
3. We use tuples for security purposes.
a 0x11
Syntax: var.add()
Syntax: var.remove()
6. Default Value: set()
Dictionary: It is a data type where data is in the form of Keys & Values where keys are
immutable and values are mutable.
{K:V, K1:V1,....Kn:Vn}
var.keys()
var.values()
var.items()
Operators: These are some symbols which have some specific meaning to work on
operands to do an operation effectively, efficiently or precisely.
In python, we have 7 types of operators:
1. Arithmetic Operators
2. Logical Operators
3. Relational Operators
4. Bitwise Operators
5. Assignment Operators
6. Membership Operators
7. Identity Operators
+ Addition 5+2=7
- Subtraction 4-2=2
* Multiplication 2*3=6
/ Division 4/2=2
// Floor Division 10 // 3 = 3
% Modulo 5%2=1
** Power 4 ** 2 = 16
Relational Operator: These are some comparison operators where you compare the
operands and get the output in the form of true or false.
== Is Equal To 3 == 5 gives us
False
Logical Operators: These are some comparison operators where we compare data
using gates.
10 9 8 7 6 5 4 3 2 1 0
2 2 2 2 2 2 2 2 2 2 2
Right Shift: Shift two places in the unit place to the right.
Left Shift: Shifts the bits of the number to the right and fills 0 on voids left.
Assignment Operator: These are the operators where we solve the operands by
having some operators, in the presence of equals to(=).
+= Addition Assignment a += 1 # a = a + 1
-= Subtraction Assignment a -= 3 # a = a - 3
*= Multiplication Assignment a *= 4 # a = a * 4
/= Division Assignment a /= 3 # a = a / 3
%= Remainder Assignment a %= 10 # a = a % 10
Identity Operator: In this operator we check the data belonging to each other with their
respective ‘ID’, we use ‘is’ and ‘not is’ operator and get the output in the form of
True/False.
is not True if the operands are not identical (do not x is not
refer to the same object) True
TypeCasting: It’s a phenomenon of converting one data type into another data type.
Syntax: var1=value
var1=data(var)
print(a)
Int Float Complex Bool String List Tuple Set Dict
Int ✓ ✓ ✓ ✓ ✘ ✘ ✘ ✘ ✘
Float ✓ ✓ ✓ ✓ ✘ ✘ ✘ ✘ ✘
Complex ✘ ✘ ✓ ✓ ✘ ✘ ✘ ✘ ✘
Bool ✓ ✓ ✓ ✓ ✘ ✘ ✘ ✘ ✘
String ✘ ✘ ✘ ✓ ✘ ✓ ✓ ✓ ✘
List ✘ ✘ ✘ ✓ ✘ ✓ ✓ ✓ ✘
Tuple ✘ ✘ ✘ ✓ ✘ ✓ ✓ ✓ ✘
Set ✘ ✘ ✘ ✓ ✘ ✓ ✓ ✓ ✘
Dict ✘ ✘ ✘ ✓ ✘ ✓ ✓ ✓ ✓
Mar 3, 2025
Print Function: Print is an inbuilt function which is used to get the input in the terminal
which is given by the user.
Input Function: Input is an inbuilt function which is used to take input or messages
from the user.
Syntax: input(‘message’)
eval(): It is an inbuilt function which is used to evaluate or validate every data type with
respective symbols.
Mar 4, 2025
1. Conditional / Decisional
2. Looping
If: It is a condition where you deal with a true body statement or true condition for your
operation.
Syntax:
if condition:
isinstance(value, datatype)
Else: It is a conditional statement where you give a false statement for a true condition.
else:
Mar 5, 2025
elif: It is a conditional statement where we have ‘n’ number of true conditions for a
single operation.
Here, every true condition is interlinked to each other where if the first condition gets
true that will not go to the second condition.
We can use ‘n’ number of elif for a single operation where else is the optional.
Mar 6, 2025
Looping: It is a control statement where we do the same set of instructions again and
again until and unless the condition becomes false.
We use looping to avoid the same set of instructions, to reduce the code size to
increase the efficiency.
1. While loop
2. For loop
While loop: It’s a looping statement where we have the same set of instructions again
and again until and unless conditions become false.
Syntax:
Initialization (i)
While condition:
Logic
Updation(Inc/Dec)
Count: It is an inbuilt function which is used to calculate the substrings from the given
string
Syntax: var.count('substring')
Syntax: car.split()
These are some standards which are followed by the computers where we give a
number to a value which is accepted universally.
Chr: It is an inbuilt function which is used to get the character with respective ascii
number.
Syntax: chr(no.)
Ord: We use order when we know the character but don’t know the number.
Syntax: ord(chr)
ord(‘a’) -> 97
chr(ord(‘a’)-32)-> A
Mar 24, 2025
Perfect number: It is a number which are sum of their factors except itself
Ex: 6
For Loop: Same set of instructions again and again until and unless the condition
becomes false. But it depends on the collection.
In For Loop, we don’t have to initialize, updation to run the loop, it will automatically take
as per collection
In For Loop, whenever we’re dealing with indexing we use range function
We can’t solve set and dict due to Any collection because we take variable
initialization
Intermediate Termination Loop: These are the loop terminators where we cut the
running loop as per user request.
Break: It is a keyword which is used to terminate the following loop at the given
condition or request.
Functions are used to reduce the code size by avoiding repetition codes where we
increase the efficiency, durability of the operation.
1. Inbuilt
2. User defined
Inbuilt Function: These are some predefined functions which have some specific task
to do. We don’t have to write code for it.
Unitary Function: These are some common inbuilt functions which are used for every
data type.
User-Defined Function: These are functions which are created with the user
requirement.
Return: It is a keyword which controls the flow of execution by assigning some values.
A✗ R✗
A✓ R✗
A✗ R✓
A✓ R✓
ex_upper() 0x11
0x11 Block of Code
Apr 7, 2025
JOIN Function: It is a function which is used to join the collection or a substring to the
collection to form a single string.
Syntax:
Def f_name():
print(f_name())
Note:
1. In these types of functions we have to pass return while calling the function.
2. We use return in the operation to control the flow of execution of the function.
Apr 9, 2025
Anagram: These are the words whose length and alphabets are the same.
Rules:
1. In this function we have to initialize all the variables in a single formal argument.
2. Create a termination code which is opposite to the looping condition using if and
store the output using return.
3. Write a logic as per requirement.
4. To update the loop or function we have to update in a single actual argument.
Generator:
A function which contains at least one yield keyword that function is known as
generator function.
Return
Return is a keyword which controls the flow of excecution by passing the value.
We use return in in normal function, recursion function.
Return don’t need any type casting to get the output.
Yield
Yield is keyword which keep the continuity of the operation by pausing the loop and
again starting from the same point.
A function which contain at least on yield keyword that function is known as generator.
It need type casting to get the output.
Local & Global Variable
Global Variable
These are the variables which are created inside the main space.
It is possible to access, modify global variable inside the main function.
It is possible to access global variable inside method area but we can’t
modify inside the function.
To modify global variable inside the function we have to use a keyword
global.
Main Space method space
a 0x11
0x11 10 print(a+b)
print(a,b)
b 0x22
0x22 20
Sum()
print(a,b) print(a+b)
print(a+b)
b=15
Local Variable
These are variables which are created inside the method space.
It is possible to access, modify local variables inside the same function.
It is possible to access local variable inside nested function but we
can’t modify directly.
We use ‘local’ keyword.
To modify local variable inside nested function we use non local
variable.
Syntax:
Class c_name:
{……….
properties
……..}
Obj = c_name()
o These are the member which belongs to the class which are
fixed for all the objects
o For example bank name bank loc, school name , school loc ,
school code
Methods: Methods are the functions which are used to access, modify the
members of class and objects.
o Object Method
These methods are use to access, modify the attributes
of the objects.
To modify, accessing the objects we have to use self.
Access – obj.f_name()
Modify = obj.f_name(value)
o Class Method
@classmethod
def f_name(cls,val):
{
}
Access Modify
@classmethod @classmethod
def f_name(cls,val):
cls.val = val
cls_name.f_name(val)_
def f_name(cls):
print(cls.val)
class.f_name()
o Static Method
private
it is access specifier where we give complete protection to the class properties which
can be accessible by the person who has given the security
Inheritance:
It’s a property of oops where we deviate properties from one class to
another class
The class which deviates properties to another class is known as
parent / super / base class
The class which acquire the property is known as child class / sub
class / derived class.
000
Parent / Super / Base Class
( Single Level:
Multi Level )
Multiple Inherictance:
It is type of inheritance where we deviate properties from multiple parent to single child
class.
CC
Syntax:
Class A:
Class B:
Class C:
Class D (A,B,C):
Hierarchical Inheritance:
Syntax:
Class A:
Class B(A):
Class C(A):
Hybrid Inheritance: These are the inheritance which are having more than one
model in a single model that models are known as Hybrid Inheritance.
PC
CC
(Heriarichal)
CC CC