Python Basics
Python Basics
Rules:
Datatypes
1) Integer
2) Float
3) String
4) Boolean
5) None
Operators
A = 10 A = 10
A = A + 10 A += 10
Print(A) Print (A)
= 20 = 20
Methods
CURD
d = {}
Create
d=dict()
d[“Key”] = “Value”
Update / Modify
update()
d[“Key”] / get()
Read / Access
keys() , values() , items()
pop() , popitem()
Delete / Remove del – keyword ( a specific key or entire
dictionary )
in – keyword
Check and Copy
copy() , dict()
Sets
Methods
CURD
Create s=sets()
add() – Single value
update() – Multiple values
Update / Modify
union()
intersection()
Read / Access
pop()
Delete / Remove
clear()
Control Flow
if ( condition ):
if ( condition ):
statements
statements
if ( condition ): elif ( condition ):
else:
statements statements
statements
else:
statement
Short Hand if
if ( condition ) : statement 1
Functions – METHODS
1)Function Arguments
1. Default
2. Positional
3. Keyword
4. Variable-length
i. Arbitrary Positional
ii. Arbitrary Keyword
Default Argument
Provide a default value for a parameter in case if no value is passed for that parameter in the
Function call. When no value is specified for the parameter in the function call.
Positional Argument
They are passed to a function by matching their position in the function call with the position
of the parameters in the function definition.
Order – Is important
Keyword Arguments
Keyword arguments allow you to pass arguments to a function by explicitly specifying the
name of the parameter and its value. This makes it easier to understand what each argument
does, especially when you have a lot of arguments with complex names or multiple default
values.
Order – Doesn’t matter
Variable-Length Argument
Sometimes we may not know the number of arguments that will be passed to a function. In
such cases, we can use variable-length arguments.
Arbitrary Positional *args
Arbitrary Keyword **kwargs
2) Lambda Function
Lambda functions are small, one-time use function that can be used as arguments for other
functions.
Syntax :
Inheritance
Class
Encapsulation Polymorphism
Object
Abstraction
Employee
Attributes Methods
Name , Age , E-mail , Blood group . To code , Give presentation , Attend
meetings , Arrange special events.
In python, every class inherits from a built-in basic class called “Object”. The constructor
(__init__) is invoked when we create an object variable or an instance of the class.
Default Constructor and Parametrized Constructor
Self-Parameter : It will point / refer to the current instance of the class. It can access the
attributes that belongs to the class. ( Object ka Reference hae )
Private Protected
Attributes can be accessed only Can be accessed even outside the
within the Class and should not be Class , yet Python will try to warn
accessed from outside the Class. you that it’s not a good idea to
If we need to access it, if there is access them outside of the Class
absolute necessary to access
private attribute then a method,
that would return the value of
private attribute, is created within
the class.
Decorators:
Methods:
Encapsulation
Access Modifiers
Private Protected
Attributes can be accessed only within Can be accessed even outside the Class , yet
the Class and should not be accessed Python will try to warn you that it’s not a good
from outside the Class. idea to access them outside of the Class