0% found this document useful (0 votes)
3 views28 pages

Python Basic Handmade Notes

Uploaded by

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

Python Basic Handmade Notes

Uploaded by

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

PYTHON COMPLETE NOTES (PART 1)

1. INTRODUCTION

Definition

Python ek High-Level, Interpreted aur Object-Oriented Programming


Language hai. Iska syntax simple aur easy-to-read hota hai, isliye beginners
ke liye best language mani jati hai.

Types

 High-Level Language

 Interpreted Language

 Object-Oriented Language

Example

print("Hello Python")

2. APPLICATIONS OF PYTHON

Definition

Python ka use alag-alag fields me software aur applications banane ke liye


kiya jata hai.

Applications

 Web Development

 Data Science

 Machine Learning

 Artificial Intelligence

 Automation

 Game Development

 Desktop Applications

3. INPUT AND OUTPUT

Definition
 Input: User se data lena.

 Output: Screen par data display karna.

Input Function

name = input("Enter Name: ")

Output Function

print("Welcome")

4. VARIABLES

Definition

Variable ek container hota hai jo data ko memory me store karta hai.

Types of Variables

Integer Variable (int)

age = 18

Float Variable (float)

price = 99.5

String Variable (str)

name = "Priyanshu"

Boolean Variable (bool)

is_pass = True

Features

 Data Store karta hai

 Memory Location ko represent karta hai

 Value change ki ja sakti hai

5. OPERATORS

Definition

Operators special symbols hote hain jo operations perform karte hain.


Arithmetic Operators

**

//

Comparison Operators

>

<

==

!=

>=

<=

Logical Operators

and

or

not

Assignment Operators

+=

-=

*=

/=

Membership Operators

in
not in

Identity Operators

is

is not

6. KEYWORDS

Definition

Keywords Python ke reserved words hote hain jinka special meaning hota
hai.

Conditional Keywords

 if

 elif

 else

Loop Keywords

 for

 while

Control Keywords

 break

 continue

 pass

Function Keywords

 def

 return

7. DATA TYPES

Definition

Data Type batata hai ki variable kis type ka data store karega.
Types

int

num = 100

float

salary = 25000.50

str

name = "Python"

bool

status = True

list

nums = [1, 2, 3]

tuple

data = (1, 2, 3)

set

items = {1, 2, 3}

dict

student = {"name": "Rahul"}

8. CONDITIONAL STATEMENTS

Definition

Conditions ke basis par decision lene ke liye use hote hain.

if Statement

if age >= 18:

print("Adult")

if-else Statement

if age >= 18:

print("Adult")
else:

print("Minor")

if-elif-else Statement

if marks >= 90:

print("A")

elif marks >= 60:

print("B")

else:

print("C")

Nested if

if age >= 18:

if age >= 21:

print("Eligible")

9. LOOPS

Definition

Loops code ko baar-baar execute karne ke liye use hote hain.

for Loop

for i in range(5):

print(i)

while Loop

count = 1

while count <= 5:

count += 1

Loop Control Statements

 break → Loop stop karta hai


 continue → Current iteration skip karta hai

 pass → Placeholder statement

10. FUNCTIONS

Definition

Function reusable code block hota hai jo specific task perform karta hai.

Built-in Function

len("Python")

User Defined Function

def greet():

print("Hello")

Function with Parameters

def greet(name):

print(name)

Function with Return Value

def add(a, b):

return a + b

Important Keywords

 def

 return

PART 1 QUICK REVISION

Python → High-Level + Interpreted Language

Variable → Data Store Karne Ka Container

Operator → Operation Perform Karne Wala Symbol

Keyword → Reserved Word

Data Type → Variable Ka Data Type Define Karta Hai


Conditional Statements → Decision Making

Loops → Repetition

Functions → Reusable Code Block

PYTHON COMPLETE NOTES (PART 2)

11. PASS STATEMENT

Definition

pass ek placeholder statement hai. Jab function, loop ya condition ka code


baad me likhna ho tab pass use karte hain.

Syntax

pass

Example

def greet():

pass

Features

 Empty block define karta hai

 Error nahi aane deta

 Future implementation ke liye use hota hai

 Function, Loop aur Conditional Statements me use ho sakta hai

12. GLOBAL AND LOCAL VARIABLES

Local Variable

Definition

Jo variable function ke andar create hota hai aur sirf usi function ke andar
use ho sakta hai.

Example

def show():
x = 10

print(x)

Global Variable

Definition

Jo variable function ke bahar create hota hai aur pure program me access
kiya ja sakta hai.

Example

x = 10

def show():

print(x)

Difference

Featur Local Global


e Variable Variable

Function ke
Scope Pure Program
andar

Access Limited Everywhere

Creatio Function ke Function ke


n andar bahar

13. RECURSION

Definition

Jab koi function khud ko call karta hai to use Recursion kehte hain.

Types

Direct Recursion

def show():

show()

Indirect Recursion
def A():

B()

def B():

A()

Features

 Code Reusability

 Complex Problems Solve Karna

 Tree Traversal

 Divide and Conquer Technique

Real Life Example

 Factorial

 Fibonacci Series

 Tree Structure

14. *ARGS AND **KWARGS

Definition

Function me multiple arguments receive karne ke liye use hote hain.

*args

Definition

Multiple positional arguments accept karta hai.

Example

def add(*args):

print(args)

Output

(10, 20, 30)


Data Type

Tuple

**kwargs

Definition

Multiple keyword arguments accept karta hai.

Example

def info(**kwargs):

print(kwargs)

Output

{'name':'Rahul','age':20}

Data Type

Dictionary

Difference

Feature *args **kwargs

Full Keyword
Arguments
Form Arguments

Data
Tuple Dictionary
Type

Positional Keyword
Accepts
Arguments Arguments

15. FIRST CLASS FUNCTION

Definition

Python me functions ko variables ki tarah treat kiya jata hai.

Function as Variable

def greet():
print("Hello")

x = greet

x()

Function as Argument

def display(fun):

fun()

Function Returning Function

def outer():

return inner

Features

 Function variable me store ho sakta hai

 Function argument ban sakta hai

 Function return ho sakta hai

 Code flexibility badhata hai

16. LAMBDA FUNCTION

Definition

Lambda ek anonymous (without name) function hota hai jo ek line me likha


jata hai.

Syntax

lambda arguments : expression

Single Argument Lambda

square = lambda x: x*x

Multiple Argument Lambda

add = lambda x, y: x+y

Features
 Anonymous Function

 One-Line Function

 Short Syntax

 Map aur Filter ke saath use hota hai

17. MAP, FILTER AND REDUCE

Definition

Ye functions collections ke data par operations perform karte hain.

MAP()

Definition

Har element par function apply karta hai.

Example

numbers = [1,2,3]

result = map(lambda x:x*2, numbers)

print(list(result))

Output

[2,4,6]

FILTER()

Definition

Condition ke according elements select karta hai.

Example

numbers = [1,2,3,4]
result = filter(lambda x:x%2==0, numbers)

print(list(result))

Output

[2,4]

REDUCE()

Definition

Sab elements ko combine karke single value return karta hai.

Example

from functools import reduce

result = reduce(lambda x,y:x+y,[1,2,3,4])

print(result)

Output

10

Difference

Functio
Work
n

Har element par


Map
operation

Condition ke according
Filter
select

Reduce Single value return

18. INNER FUNCTION


Definition

Jab ek function ke andar dusra function define kiya jata hai to use Inner
Function kehte hain.

Example

def outer():

def inner():

print("Inner Function")

inner()

Features

 Data Hiding

 Better Security

 Code Organization

 Reusability

19. DECORATORS

Definition

Decorator ek special function hota hai jo kisi dusre function ki functionality


ko modify ya enhance karta hai bina original function ko change kiye.

Simple Decorator

def decorator(func):

def wrapper():

print("Before Function")

func()
print("After Function")

return wrapper

Decorator with Arguments

def decorator(func):

def wrapper(name):

func(name)

return wrapper

Features

 Code Reusability

 Function Enhancement

 Clean Code

 Easy Maintenance

PART 2 QUICK REVISION

pass → Placeholder Statement

Local Variable → Function Ke Andar

Global Variable → Function Ke Bahar

Recursion → Function Calls Itself

*args → Multiple Positional Arguments

**kwargs → Multiple Keyword Arguments

First Class Function → Function Ko Variable Ki Tarah Treat Karna

Lambda Function → Anonymous One-Line Function

Map() → Har Element Par Operation


Filter() → Condition Ke According Select

Reduce() → Single Value Return

Inner Function → Function Ke Andar Function

Decorator → Function Ki Functionality Enhance Karna

PYTHON COMPLETE NOTES (PART 3)

20. STRINGS

Definition

String characters ya text ka collection hota hai. String Immutable hoti hai,
yani create hone ke baad change nahi ki ja sakti.

Types

Single Quote String

name = 'Python'

Double Quote String

name = "Python"

Triple Quote String

text = '''Python'''

Multiline String

text = """Hello

Python"""

Features

 Ordered

 Immutable

 Indexing Supported

 Slicing Supported

 Duplicate Characters Allowed

Important String Methods


upper()

String ko uppercase me convert karta hai.

[Link]()

lower()

String ko lowercase me convert karta hai.

[Link]()

title()

Har word ka first letter capital karta hai.

[Link]()

capitalize()

Sirf pehla character capital karta hai.

[Link]()

replace()

Text replace karta hai.

[Link]("Python", "Java")

split()

String ko list me convert karta hai.

[Link]()

join()

List ko string me convert karta hai.

"-".join(["a","b","c"])

strip()

Extra spaces remove karta hai.

[Link]()

find()

Character ya word ki position batata hai.

[Link]("P")
count()

Occurrence count karta hai.

[Link]("a")

startswith()

Starting check karta hai.

[Link]("Py")

endswith()

Ending check karta hai.

[Link]("on")

Built-in Functions

len(text)

max(text)

min(text)

sorted(text)

str(123)

21. LIST

Definition

List ek Ordered aur Mutable Collection hai jisme duplicate values allow
hoti hain.

Types

Integer List

numbers = [1,2,3]

String List

names = ["Rahul","Aman"]

Mixed List

data = [1,"Python",3.5]
Nested List

matrix = [[1,2],[3,4]]

Features

 Ordered

 Mutable

 Duplicates Allowed

 Indexing Supported

 Slicing Supported

Important Methods

append()

Element add karta hai.

[Link](10)

extend()

Multiple elements add karta hai.

[Link]([20,30])

insert()

Specific position par add karta hai.

[Link](1,15)

remove()

Specific element remove karta hai.

[Link](10)

pop()

Last element remove karta hai.

[Link]()

clear()

Puri list empty karta hai.

[Link]()
index()

Element ki position batata hai.

[Link](20)

count()

Occurrence count karta hai.

[Link](10)

sort()

Ascending order me sort karta hai.

[Link]()

reverse()

List reverse karta hai.

[Link]()

copy()

List ki copy banata hai.

[Link]()

22. TUPLE

Definition

Tuple ek Ordered aur Immutable Collection hai.

Types

Integer Tuple

numbers = (1,2,3)

String Tuple

names = ("Rahul","Aman")

Mixed Tuple

data = (1,"Python",3.5)

Nested Tuple
data = ((1,2),(3,4))

Features

 Ordered

 Immutable

 Duplicates Allowed

 Indexing Supported

Methods

count()

[Link](1)

index()

[Link](2)

23. DICTIONARY

Definition

Dictionary data ko Key : Value Pair format me store karti hai.

Features

 Ordered

 Mutable

 Unique Keys

 Fast Searching

 Key-Value Pair Format

Important Methods

get()

[Link]("name")

keys()

[Link]()

values()
[Link]()

items()

[Link]()

update()

[Link]({"age":20})

pop()

[Link]("name")

popitem()

[Link]()

setdefault()

[Link]("city","Delhi")

copy()

[Link]()

clear()

[Link]()

fromkeys()

[Link](["a","b"],0)

24. SET

Definition

Set unique elements ka Unordered Collection hai.

Features

 Unordered

 Mutable

 Unique Elements

 No Indexing

 No Duplicates
Important Methods

add()

[Link](10)

update()

[Link]([20,30])

remove()

[Link](10)

discard()

[Link](10)

pop()

[Link]()

clear()

[Link]()

union()

[Link](b)

intersection()

[Link](b)

difference()

[Link](b)

symmetric_difference()

a.symmetric_difference(b)

25. ARRAYS

Definition

Array same data type ke multiple elements store karta hai.

Example

from array import array


numbers = array('i',[1,2,3])

Features

 Same Data Type

 Fast Processing

 Memory Efficient

 Sequential Storage

Important Methods

[Link](10)

[Link]([20,30])

[Link](1,15)

[Link](10)

[Link]()

[Link](10)

[Link](10)

[Link]()

[Link]([1,2])

[Link]()

26. LIST COMPREHENSION

Definition

List Comprehension ek short aur efficient way hai list create karne ka.

Syntax

[expression for item in iterable]

Types

Simple List Comprehension

[x for x in range(5)]
With Condition

[x for x in range(10) if x%2==0]

With Expression

[x*x for x in range(5)]

Nested List Comprehension

[[i*j for j in range(3)] for i in range(3)]

Features

 Less Code

 Better Readability

 Faster Execution

 Loop Replacement

27. DICTIONARY COMPREHENSION

Definition

Dictionary Comprehension dictionary create karne ka short aur efficient way


hai.

Syntax

{key:value for item in iterable}

Types

Simple Dictionary Comprehension

{x:x*x for x in range(5)}

With Condition

{x:x*x for x in range(10) if x%2==0}

Existing Dictionary

{k:v+5 for k,v in [Link]()}

Features

 Less Code
 Better Performance

 Easy Dictionary Creation

 Readable Syntax

DATA STRUCTURE COMPARISON TABLE

Lis Tupl Se Dictiona


Feature
t e t ry

Ordered Yes Yes No Yes

Mutable Yes No Yes Yes

Duplicate
Yes Yes No Keys No
s

Key
Indexing Yes Yes No
Based

QUICK REVISION

List

Ordered + Mutable

Tuple

Ordered + Immutable

Set

Unique Elements + Unordered

Dictionary

Key-Value Pair Collection

String

Ordered + Immutable Text

Array

Same Data Type Elements

List Comprehension
Short Way To Create Lists

Dictionary Comprehension

Short Way To Create Dictionaries

You might also like