0% found this document useful (0 votes)
4 views22 pages

Python Notes

The document provides an overview of Python programming, including its history, features, data types, and key concepts such as variables, identifiers, and operators. It explains the structure and properties of various data collections like lists, tuples, sets, and dictionaries, as well as the use of functions and loops. Additionally, it covers memory allocation, typecasting, and the types of arguments in function calls.

Uploaded by

thakurdevil340
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views22 pages

Python Notes

The document provides an overview of Python programming, including its history, features, data types, and key concepts such as variables, identifiers, and operators. It explains the structure and properties of various data collections like lists, tuples, sets, and dictionaries, as well as the use of functions and loops. Additionally, it covers memory allocation, typecasting, and the types of arguments in function calls.

Uploaded by

thakurdevil340
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Notes

History of Python
• Discovered by Guido Van Rossum in the year 1991
Features of Python
1. Its is High Level Programming Language
2. Easy to read write and analyze
3. Python is Both Compiler and Interpreter Based
4. Python is a scripting language
5. Huge Library
6. Python is Dynamically Typed Programming Language
7. Platform Independent
8. Large Community Support
9. Object Oriented Programming
10. Free and Open Source
Python Library is categorized into 3 types
1st Keywords
2nd Operator or Special Symbols
3rd Inbuilt Functions
Key Words
1. Key Words are Predefined Words Having its own Functionality
2. 'False', 'None', 'True', Are Special Keywords Because These Can be used as a value
Variable
Variable is a Container in which we can store our data or value . It Stores Adress Reference
Memory allocation
a=10
b=10
Range -5 to 256 if two variables are having same value and they are in the range between -5
to 256 then only they will share the same memory address
id (Variable Name) this will return address
Float range
C=29.8
C 1934XO

1934XO 29.8
• a = 10 – single variable creation
• a,b,c = 7,4,6 – multiple variable creation
• Variable Name Function
• a = 7,10,4,5 – tuple = single variable with multiple values it is not compulsory that it
should contain brackets
NOTE : Every identifier is a variable name.
Identifier
The names given to a variable, function, class, module are known as identifiers
Rules of identifiers
1. It should not be a keyword
2. It should not start with no but it can be alpha numeric
Ex: 06adi = 10 (wrong) Adi06 = 64 (correct)
3. It Should not contain space in between
4. It should not contain any special symbols except _
Note: Length of the identifier should not be more than 78 according to industrial standard
Data types
type(variable_name) #This will tell the datatype
A=10
Print(type(A)) – tells us that variable is of which type
1. Integer = -infinity to +infinity (without decimal points)
• By default value for integer is zero
2. Float = -infinity to +infinity (with decimal points)
• By default value for float is 0.0
3. Complex = +a,-a,+bj,-bj
• In python, j is considered as default imaginary value
• Imaginary is divided into two parts – real and imaginary
4. Boolen = Either True or False
• By default is false
5. String = collection of characters
• Enclosed in either single quote or double quote or triple quote
NOTE : There are two methods to replace particular character in string firstly is typecasting
and secondly using slicing.
1. Typecasting : convert into a mutable datatypes and then u can proceed
2. Slicing : use slicing upto the last character and add a character to edit and then proceed the
slicing.
Indexing
Assigning sub address. Index are the Sub address of each Characters
L to R →+ve index → 0 to len -1(collection)
R to L → -ve index → -1 to len (collection)
NOTE : index is used to check the sub address of each character. List is mutable but if there
is a element that is immutable then we can edit the element of that. But we can edit that full
element as it is stored in as a element.
PROPERTIES OF STRING :
• It supports indexing.
• It is immutable – fetch, access
• Ex – “aditya” – modification is not possible
Syntax: • Var{step position , end position (±1),Step Size}
Default value –> start end—last index (step size – 1)
List
List is a collection of characters enclosed inside square brackets. Separated by commas (,) It
can store – single value as well as multi type datatype
NOTE : [Link](5) – it inserts the value at the end of the collection
Modification

Tuple
It is a immutable collections of values enclosed inside paranthesis (). Indexing supports then
also slicing possible hai. values separated by commas. (bakchodi allowed nhi hai)
Set
It is an unordered non duplicated collection of data items. Represented inside curly bracses
{}. It does not support indexing. It is mutable.
INBUILT FUNCTIONS OF SETS :
1. add() : it will add new value to existing set
2. remove() : when you pass a value, it will remove a specific value
3. pop(): it will randomly pop any element
a. bydefault removes element randomly.

b.
DICTIONARY
It is a collection of key and value pair enclosed inside curly brases {} and separated by
commas (,).
NOTE : KEY ➔ IMMUTABLE
VALUE ➔ MUTABLE
# access value – var[key]
# modify – var[key] = value
NOTE : key ko modify nhi kr skte.
Copy Operation
In python we have three types of copy operation
1 General copy
Memory allocation get stored where same value of variable get stored by using same
location

NOTE : agr a ko change krenge toh b ve change hoga. Yhi ese ke dikkat hai and a = 31 khtm
ho jayega. Yhe dikkat hai. Simple example hai ke jese hm cheating krte hain agr uske galti
huye toh hmari ve glti hogi simple.

A OX11

OX11 10

OX11
2 Shallow Copy
Here New address get formed

3 Deep Copy
Typecasting
Converting 1 Data Type to another

Typecasting Error
Types of Operators –
In python, we have some special symbols which we use to perfrom special operations. In
python we have 7 types of operators.
7 types of Operators

Arithmetic
1 Addition(+) Add Values (Add Operation)
Concatenation➔s1=”adi”
S2=”tya”
Print(S1+S2) #Output = aditya
2 Subtraction(-) Subtract Values
3 Multiplication(*)

4 Division
5 Power / Exponential(**)
10**3➔

Relational Operator

Gives Output in True and Fale (Boolean)

A=10
B=10.0
print(A==B) #Output True print(type(A)==type(B)) #Output False
Logical Operators

Assignment Operator

Membership Operator
In , not in
Identity Operator
Is, is not ➔ they check the address

Bitwise Operator

Eval
Input & Output Statements

Conditional Statements
Whenever you write conditional statement then you give thinking capacity to the code
--->simple if
--->if-else
--->elif
--->nested if

1. Single If
Example

2. If-else
if condition:
{TSB
else:
{FSB
3. If-elif-else
if condition:
{TSB
elif condition:
{TSB
else:
{FSB

4. Nested if
if condition :
if condition:
{TSB
else:
{FSB
else:
{FSB
f-string / Formatted String
name=input()
age=int(input())
print(f”hi my name is {name} and age is {age}”)

Loops
Loop Used to perform the same task multiple times in short code using loops
➔For Loop
➔While Loop
Used to perform the same task multiple times in short code using loops
While Loop
Step 1 Initilization
Step 2 Syntax while condition
{While body
{ (Set of instruction block of code)
Step 3 Updation Statement

Example
For Loop

Difference between while and for loop

Nested Loops
Functions
These are of two types
Inbuild – These functions are already defined pehle seh
For Example- count,len,pop
User-Defined- Those functions which are designed by the user
Function Declaration

def function_name (arguments):


{Function Body
function_name(arguments)

Function call
Function are of 4 types
1. Without argument and without return type.
2. Without argument with return type
3. With argument without return type
4. With argument with return type
Memory Allocation
Argument

• Function increases reusability of the code.


• Function will not execute, neither it will throw error unless you call that function.
• Return: It will unload the function from execution and carry forward the value to
where ever the function was called.

• Whenever you pass argument to the function it means the code is dynamic.
Types of Arguments
Positional Argument
• Number of variables must be equal to the number of values (arguments) during
function call.
OR
• Number of values/arguments during function call must be equal to the number of
arguments given during function declaration.
• Assigning of values will be similar to the sequence given during declaration.

Keyword Argument

• If you are using keyword argument first, then it must be followed with keyword
arguments.
• You can’t pass a positional argument after a keyword argument.


Default Argument

You might also like