Python q
Python q
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’
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']
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.
We have two types of slicing:
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.
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()
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.
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.
Bitwise Operator: This operator is used to compare the data using binary methods and
give you output in the form of numbers.
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
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 ✘ ✘ ✘ ✓ ✘ ✓ ✓ ✓ ✓
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:
Else: It is a conditional statement where you give a false statement for a true condition.
If 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
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.
Apr 2, 2025
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.
Example: print(), input(), eval(), id(), type(), bool()
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.
Ex: Silent = Listen
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.