Core Python
In this context, parameters where number of variations we study about multiple
forms, and we have data where we can manipulate our data.
Core Python Includes:
• Python Basics
• Data Types
• Data Structure
• Decision Making
• Loops
• Try Except
• OOPS
• Regular Expression
All above content come under Core, where we can manipulate our data with functions
and manage it.
Python Basics
• Python is case sensitive
• To store data, we use variables
C=2+2
IC = 2 + 2 X
C1 = 2 + 2
CE = 2X
C-C=2V
$c = 2 X
Quotation (Catation)
x = 'hello'
"hello world"
"my name is..."
→ Single and double string can be interchanged, but pass triple string only for
paragraph.
Data Types
1) Integer (int)
int 64 numbers → 42, 52, 72…
2) Float
float 64 → decimal values
Example → 6.2, 9.29… (point values)
3) String (str)
Letters, sentence
→ String objects are also denoted as text.
4) Date/Time
Date, time → includes date and time values
64+ date and time
Data Structures
Data structures are different types of data types used for storing data.
→ As data types in Python are loosely typed ...Loose typing means: we can pass
data type automatically, no need to define it, as it detects automatically.
1) List
List is enclosed in square brackets []
List is mutable
→ Means manipulation possible hai
We can:
update
insert
delete
edit
Example:
[Link](100) # add karega
[Link]() # delete karega
L[1] = 200 # update karega
L = [1, 200, 4, 5]
Note
• If data which has no brackets is passed, it is treated as elements, and default data
structure is tuple.
Example
e = 1, 2, 3
e
# (1, 2, 3)
Dictionary (dict)
Dict is enclosed in curly brackets {}
It is also known as key value pair
Data and its formation time depend on their data structure
Dict is mutable
→ Manipulation possible
Example:
d = {'a': 'apple', 'b': 'ball'}
d['c'] = 'cat' # insert
d['a'] = 'anar' # update
d
# {'a': 'anar', 'b': 'ball', 'c': 'cat'}
→ In dict, key ko call karenge to access hogi
4) Set
Set is where values are enclosed in curly brackets {}
It allows only unique values
→ No duplications allowed
Example:
S = {1, 2, 3, 3, 3, 4, 4, 5, 5, 6}
S
# {1, 2, 3, 4, 5, 6}
OOPS (Object Oriented Programming)
Object
Object is combination of data and procedures
It is also known as a single unit with methods
Class
Class is a user defined structure or prototype
Used to store multiple methods/functions
Example:
def curve(x1, x2, y1, y2):
cu = (y2 - y1) / (x2 - x1)
print("Curve is", cu)
curve(1, 2, 3, 4)
→ Jis bhi variable ko def pass hoga, uska function ban jayega
Indentation
Indentation means code should be in some order where we can execute our
data.
This indentation only works when you have some header file / reserved
keyword
Class
Class holds multiple functions
→ “Agar ek se zyada function hai, to wo class ke andar aayenge
Example
class Phy:
def Avg_Speed(d, t):
s=d/t
print("Avg Speed is", s)
def Acc(v, u, t):
a = (v - u) / t
print("Acc is", a)
P = Phy
Above example clearly states that formation of data and multiple functions
come under the class.
Data treated and formed by number of variables in it.
→ “Class banate waqt always first letter Capital”
Instance Object
P = Phy
[Link](1, 2, 3)
[Link](5, 7)
P.Avg_Speed(214)
→ OOPS deals with the automation of our functions, where the formation is to
automate our code
→ “Jo bhi manual function hai, use OOPS ke through automate karenge”
Function and Class
def → ek function
If more functions come, then they are written under class.
def function1():
pass
class MyClass:
def function2():
pass
def function3():
pass
Class Formula
Class contains more than 1 function
Example: def cm_to_m(cm): # This function takes input (requirement)
m = cm / 100 # Formula
print("Meter is", m) # To print
Concept Explanation
Above function holds the feature which is distributed and formed, where
data structure is used.
This indicates the formation and applicable format to integrate new features.
→ “Jo bhi task ko automate karna hai, uske feature formula mein add karenge”
Clear data can be customized when it has proper formation, and this
involves structure.
Instance Object with Functions
f = Formula # instance object
f.cm_to_m(1000)
f.Avg_Speed()
f.cm_to_m()
f.m_to_cm()
Functions like:
Avg_Speed
cm_to_m
m_to_cm
→ All can be accessed using instance object
MRO (Method Resolution Order)
Creating Python Script for Automated Code
Step 1
Convert the Jupyter extension into .py
→ { .ipynb to .py }
Step 2
([Link]) is our Python file which holds compiled code
Step 3
Environment: Jis environment mein .py file rahegi, wahi par code run hoga
Steps Conclusion
Above steps will create a new library, which is units
This is a user-defined library
Inheritance
Inheritance means one class can use the properties and functions of
another class
→ Code reuse possible hota hai
class A:
def func1():
print("Function 1")
class B(A): # Inheriting class A
def func2():
print("Function 2")
→ Yaha class B, class A ke features use kar sakti hai
→ “Jo bhi existing code hai, usko reuse karne ke liye inheritance use karte hain”