Extra gyaan that’s more like a tip:
Whenever you feel like a variable can only have either this value or this value like in prime checker
we use flag = 0 or 1
It’s a good programming practice to use Boolean value ie True or False instead of using these
variables like flag.
A set is an unordered collection of unique elements. It is mutable tho.
StopIteration Is an exeption used in iteration to tell the next() function to stop.
This is fun() -> execution but this fun -> reference passing.
Encapsulation means capsule mein dalna like apne liye accessible rkhna but bhr walo kein liye not
accessible it is done with the help of private variables that are modified and accessed via get_ and
set_ methods.
In Python, a class variable is a variable that is shared by all instances of a class. It is
defined inside the class but outside any instance methods (like __init__).
In Python, a static method is a method that belongs to a class but does not have access to the
class's instance or class-specific attributes. It is defined using the @staticmethod decorator
and does not take self or cls as its first argument. Static methods are essentially functions that
are grouped within a class because they logically belong there. They are called on the class
itself, not on an instance of the class.
Python doesn’t allow empty code blocks. If you leave a function, loop, or class empty, you'll
get an IndentationError. pass prevents that by acting as a no-op filler.In Python, pass is a null
statement — it does nothing. It's used as a placeholder where code is syntactically required
but you don’t want to write anything (yet).
Just like switch(value) we have match(value) in python and instead of default : we have
something like case
H
What I am not getting at all ☹
1. Closure Function
2. OOP last part
3. Decorators
07:Numbers in depth in python
In python power is given by ‘**’
Sir ne kaha hai variables ke naam dene mein kanjoosi mat krna like don’t say count rather
positive_number_count so that you can make production level code.
This ‘+’ operator can be used at many places like ‘3+4’ or ‘ashu + tosh’ this property of an operator is
called operator overloading.
To get higher precision on any number (as you should know that python unlike other languages has
capability to evaluate several expression completely like 2 ** 100000 ! ) you can use several methods
but this method is used in numpy
f-strings (formatted string literals) were introduced in Python 3.6. They allow you to embed
expressions directly inside string literals, using curly braces {} and prefixing the string with f.
pi = 3.1415926535
print(f"{pi:.2f}")
# Output: 3.14
Difference between repr(), print() and str()
Repr() : Jo jaisa hai waisa hi return hoga (used for developers)
Str(): Returns a string ( focus on point returns!)
Print(): prints a string (internally print(str(obj)) )
In python True has capital “T” same for False , but as in python a lot of stuff are treated as number so
true also means 1 and false means 0 .
In python x<y<z means (x<y and y<z)
Similarly x==y<z means (x==y and y<z)
Python supports decimal octal binary….. several bases of numbers.
0o20 means octal of 20
0xFF means decimal of hexadecimal FF
0b1000 means decimal of binary 1000
We can also convert any base value into any base value by this syntax
Int (‘64’, 2) - > 100 this means convert 64 int into base 2 ie binary value
Int (‘10000’, 2) -> 16
There is also something called shift operators
Like if x = 1
Then if we do x << 2 ( this means shift x left by 2 bits making it 0100)
We will get 4
0.1 has no exact binary representation → small rounding errors → math isn’t "perfect".
So to solve this issue specially in banking and calculation import Decimal module,
from decimal import Decimal
x = Decimal('0.1') + Decimal('0.1') + Decimal('0.1') - Decimal('0.3')
print(x) # Output: 0.0
Similar problem arrises for fraction as well,
Empty braces means empty dictionary to declare an empty set use set().
Set is same as the maths wala set.
String
During web development we may use string_name.strip() to remove extra spaces.
If you want to convert string into list use string_name.split(“, ”) this means if comma with space mila
toh split without taking these “, “
There is something called place holders { } and we can add variables in it,
If you want to count the number of times a character appears in a given string you can use count( )
function like this,
String_name.count(char_u_wanna_search)
We can also convert list into string
There are some special ways to print stuff using print statement
This r” “ means raw string and it is useful when dealing with windows directory.
(lec 09) List in python
Always rem that in python ki duniya array = list.
This is common thing you will see in python
This print( ) thing in pthon has one extra thing called end which by default has \n you can change it
easily by this
Print(what_you_want_to_print, end=’-’)
There are several methods of list that are very English like
If tea_you_want in teas:
#do this
List.append(), list.pop(), list.insert(position, what?), list.copy()
Nd ! this is the reason why python is python
This the only thing I found interesting in dictionary
Conditionals and Loops (10 questions 😊 each)
We can use exit( ) function to exit our entire program whereas use break to escape from current
scope like in loops.
Starting mein hi sir told that in python loops are not just iteration they created another take on this
thing.
for variable in iterable:
so basically instead of doing i++ we do in range(start , end) by default range(5) means 0,1,2..4 obvio
not 5 😊
An f-string (short for formatted string literal) is a feature in Python 3.6 and above that allows you to
embed expressions directly inside string literals, making your code cleaner and more readable.
name = "Ashu"
age = 21
print(f"My name is {name} and I am {age} years old.")
Basically in python we have iteration tool to perform iteration like for, while etc which applies this
iter() or __iter__() function on objects that can be iterable (like lists, file(though little diff) )
When iter() is applied on iterable obj it returns first address then we use __next__() or next() which
lets us jumps to next memory location and will stop like when reaches 4 in eg by giving an exception
StopIteration which is in gen handled beautifully by iteration tools like for, newline() etc.
Functions :
Function Defination :
def function_name (parameters) :
#code to be executed
Function_name(arguments)
Parameters are place holders whearas arguments are actual value.
Polymorphism simply means ek chiz anek kaam.
Lambda Function : Functions likhne aur use krne ka ek aur tareeka hai sir said it is mostl used in
Django and flask but abhi ke liye bs itna smjho tht its just a way of writing a function
Cube = lambda x : x ** 3 #takes a numb and makes its cube.
Functions with *args:
If you just print(args) you will find a tuple.
Functions with **kwargs:
Its just a diff way to pass arguments to the functions. Sir said we will be using this later on.
Okay so I come across this yield() used in generator functions,
return → gives one final value and ends the function.
yield → gives a value but remembers where it left off, so next time you call it, it
continues from there.
Scope and Closure (16) :
Scope in terms of memory aese smjh skte hai ki by scope of anything means hum main memory
mein ek space bana rhe hai / ek ghr bana rhe hai / ek namespace bana rhe hai
“Bahar se andr aa skte ho lekin ghr ki chize bhr nhi jani chahiye”
This bhr bhr nikalte jana to find is also called “climbing” and is found in several programming
languages.
You have a toy box (a function) that has a small toy inside (another function).
But when you take the toy out, it still remembers what was inside the toy box! ---closure
It is useful when “You want to remember some data without using global variables and You want to
create custom functions with remembered info.”
Object Oriented Programming in Python 😊
OOP is nothing but just creating forms ( dhacha) jispe each person can write his own stuff ( gujiya)
Class is template whereas objects are a particular instance of that class.
This __init__() is also called constructor which is a method which is executed whenever a object of a
class is created.
Self refers to the instance of the class through which a method or attribute is accessed.
Super() is a keyword used in child class to access something in parent class.
The super() keyword in Python is used to call methods from a parent (or superclass). It's most
commonly used inside a subclass to:
Call the constructor of the parent class.
Call other methods defined in the parent class.
It helps you reuse code from the parent class without repeating it, and makes your code more
maintainable—especially in inheritance or multiple inheritance scenarios.
If you put two underscores __ before any attribute of an class it becomes private attribute ie its
accessible only within the class objects won’t know about it but,
It is accessible to objects via a special methods by conventioned named as get_<attribute name>()
Similarly they are setted via special method by conventioned named as set_<attribute name>()
o