рддो рд╕्рд╡ाрдЧрдд рд╣ै рдЖрдкрдХा। ЁЯСЛ
рдЕрдЧрд░ рдЖрдк Programming рд╕ीрдЦрдиा рдЪाрд╣рддे рд╣ैं, рддो Python рд╕рдмрд╕े popular рдФрд░ beginner-friendly programming languages рдоें рд╕े рдПрдХ рд╣ै। рдЗрд╕рдХा syntax рдХाрдлी simple рд╣ै рдФрд░ рдЗрд╕ी рд╡рдЬрд╣ рд╕े beginners рдХे рд▓िрдП Python рд╕े programming рд╢ुрд░ू рдХрд░рдиा рдЖрд╕ाрди рд░рд╣рддा рд╣ै।
Python рдХा рдЗрд╕्рддेрдоाрд▓ рдЖрдЬ Web Development, Data Science, Artificial Intelligence, Machine Learning, Automation, Cybersecurity, Game Development, Desktop Applications рдФрд░ Scripting рдЬैрд╕े рдмрд╣ुрдд рд╕ाрд░े рдХ्рд╖ेрдд्рд░ों рдоें рдХिрдпा рдЬाрддा рд╣ै।
рд▓ेрдХिрди Python рд╕ीрдЦрддे рд╕рдордп рдПрдХ problem рдЖрддी рд╣ै—рдЬैрд╕े-рдЬैрд╕े рдЖрдк рдЖрдЧे рдмрдв़рддे рд╣ैं, рд╡ैрд╕े-рд╡ैрд╕े рдмрд╣ुрдд рд╕ाрд░े Functions, Methods, Operators, Modules, Classes рдФрд░ Concepts рд╕ाрдордиे рдЖрдиे рд▓рдЧрддे рд╣ैं।
рдЗрд╕ीрд▓िрдП рдЗрд╕ article рдоें рд╣рдордиे Python рдХा рдПрдХ Complete Cheat Sheet рддैрдпाрд░ рдХिрдпा рд╣ै।
рдЗрд╕рдоें рдЖрдкрдХो Python рдХे 500+ important Functions, Methods, Concepts рдФрд░ Features рдЖрд╕ाрди рднाрд╖ा рдоें рдоिрд▓ेंрдЧे।
рдЖрдк рдЗрд╕ article рдХो Python рд╕ीрдЦрдиे рдХे рд╕ाрде-рд╕ाрде Quick Revision Guide рдХी рддрд░рд╣ рднी рдЗрд╕्рддेрдоाрд▓ рдХрд░ рд╕рдХрддे рд╣ैं।
ЁЯТб рдоेрд░ा рдЕрдиुрднрд╡
Python рд╕ीрдЦрддे рд╕рдордп рд╕рдмрд╕े рдкрд╣рд▓े рдЖрдкрдХो Syntax рдФрд░ Basic Concepts рд╕рдордЭрдиे рдЪाрд╣िрдП। рд╢ुрд░ुрдЖрдд рдоें рдХेрд╡рд▓ рдмрд╣ुрдд рд╕ाрд░े Functions рдпाрдж рдХрд░рдиे рдХी рдХोрд╢िрд╢ рдХрд░рдиा рд╕рд╣ी рддрд░ीрдХा рдирд╣ीं рд╣ै।
рдкрд╣рд▓े:
Variables → Data Types → Operators → Conditions → Loops → Functions → Collections
рдХो рдЕрдЪ्рдЫी рддрд░рд╣ рд╕рдордЭें।
рдЗрд╕рдХे рдмाрдж:
OOP → Modules → File Handling → Exceptions → APIs → Libraries → Projects
рдХी рддрд░рдл рдмрдв़ें।
Python рдХी рд╕рдмрд╕े рдЕрдЪ्рдЫी рдмाрдд рдпрд╣ рд╣ै рдХि рдЗрд╕рдХा Code рдкрдв़рдиे рдоें рднी рдХाрдлी рдЖрд╕ाрди рд▓рдЧрддा рд╣ै। рд▓ेрдХिрди рд╕िрд░्рдл Code рдкрдв़рдиा рдХाрдлी рдирд╣ीं рд╣ै।
Code рд▓िрдЦिрдП → Run рдХीрдЬिрдП → Error рджेрдЦिрдП → Error рд╕рдордЭिрдП → рдлिрд░ рджोрдмाрд░ा Try рдХीрдЬिрдП।
рдпрд╣ी Python рд╕ीрдЦрдиे рдХा рд╕рдмрд╕े рдЕрдЪ्рдЫा рддрд░ीрдХा рд╣ै।
Python рдХ्рдпा рд╣ै?
Python рдПрдХ high-level, general-purpose programming language рд╣ै।
Python рдХा рдЗрд╕्рддेрдоाрд▓ рдХрдИ рддрд░рд╣ рдХे рдХाрдоों рдХे рд▓िрдП рдХिрдпा рдЬाрддा рд╣ै:
Web Development
Data Science
Artificial Intelligence
Machine Learning
Automation
Scripting
Cybersecurity
Game Development
Desktop Applications
Scientific Computing
Data Analysis
API Development
рдПрдХ simple Python program:
print("Hello World!")
Output:
Hello World!
Python рдХी рдЦाрд╕ рдмाрдд рдпрд╣ рд╣ै рдХि рдЗрд╕рдоें code рдХाрдлी clean рдФрд░ readable рд╣ोрддा рд╣ै।
Python рдХैрд╕े Install рдХрд░ें?
Python рдХो install рдХрд░рдиे рдХे рдмाрдж рдЖрдк рдЗрд╕े Terminal, Command Prompt, IDLE рдпा рдХिрд╕ी Code Editor рдЬैрд╕े VS Code рдоें рдЪрд▓ा рд╕рдХрддे рд╣ैं।
Version check рдХрд░рдиे рдХे рд▓िрдП:
python --version
рдпा:
python3 --version
Python interpreter рд╢ुрд░ू рдХрд░рдиे рдХे рд▓िрдП:
python
Program run рдХрд░рдиे рдХे рд▓िрдП:
python app.py
Python Comments
Comments рдХा рдЗрд╕्рддेрдоाрд▓ code рдХो рд╕рдордЭाрдиे рдХे рд▓िрдП рдХिрдпा рдЬाрддा рд╣ै।
Single Line Comment
# This is a comment
Multi-Line Style
"""
This is a
multi-line comment style
"""
рдз्рдпाрди рд░рдЦें рдХि triple quotes technically string literals рд╣ैं, рдЬिрди्рд╣ें рдЕрдХ्рд╕рд░ documentation рдпा multi-line text рдХे рд▓िрдП рдЗрд╕्рддेрдоाрд▓ рдХिрдпा рдЬाрддा рд╣ै।
Python Variables
Python рдоें variable рдмрдиाрдиे рдХे рд▓िрдП рдХिрд╕ी special keyword рдХी рдЬрд░ूрд░рдд рдирд╣ीं рд╣ोрддी।
name = "Rahul"
age = 20
city = "Delhi"
Value рджेрдЦрдиे рдХे рд▓िрдП:
print(name)
Variable рдХा type:
type(age)
Python Variable Naming Rules
Variable:
Letter рд╕े рд╢ुрд░ू рд╣ो рд╕рдХрддा рд╣ै।
_рд╕े рд╢ुрд░ू рд╣ो рд╕рдХрддा рд╣ै।Number рд╕े рд╢ुрд░ू рдирд╣ीं рд╣ो рд╕рдХрддा।
Space рдирд╣ीं рд╣ोрдиा рдЪाрд╣िрдП।
Case-sensitive рд╣ोрддा рд╣ै।
Python keywords рдХो variable name рдХे рд░ूрдк рдоें рдЗрд╕्рддेрдоाрд▓ рдирд╣ीं рдХрд░рдиा рдЪाрд╣िрдП।
рдЙрджाрд╣рд░рдг:
name = "Rahul"
_name = "Aman"
age2 = 25
рдЧрд▓рдд:
2name = "Rahul"
Python Data Types
Python рдоें рдХрдИ important built-in data types рд╣ैं:
| Data Type | Example |
|---|---|
str | "Hello" |
int | 25 |
float | 10.5 |
complex | 2+3j |
bool | True |
list | [1, 2, 3] |
tuple | (1, 2, 3) |
set | {1, 2, 3} |
dict | {"name": "Rahul"} |
NoneType | None |
bytes | b"Hello" |
bytearray | bytearray(5) |
range | range(5) |
String
String Text Data рдХो store рдХрд░рдиे рдХे рд▓िрдП рдЗрд╕्рддेрдоाрд▓ рд╣ोрддी рд╣ै।
name = "Lovejeet"
Single Quotes:
name = 'Lovejeet'
Double Quotes:
name = "Lovejeet"
Multi-line String:
message = """Hello
Welcome to Python"""
String Indexing
text = "Python"
рдкрд╣рд▓ा character:
text[0]
Output:
P
Last character:
text[-1]
Output:
n
String Slicing
text = "Python"
text[0:3]
Output:
Pyt
рдХुрдЫ useful examples:
text[:3]
text[3:]
text[:]
text[::2]
text[::-1]
500+ Python Functions, Methods рдФрд░ Concepts
рдЕрдм рд╣рдо Python рдХे рд╕рдмрд╕े рдЬрд░ूрд░ी Functions, Methods рдФрд░ Concepts рдХो category-wise рджेрдЦрддे рд╣ैं।
Python Built-in Functions
Python рдоें рдХрдИ built-in functions рдкрд╣рд▓े рд╕े available рд╣ोрддे рд╣ैं।
рдХुрдЫ рд╕рдмрд╕े рдЬрд░ूрд░ी Functions:
abs()
all()
any()
ascii()
bin()
bool()
breakpoint()
bytearray()
bytes()
callable()
chr()
classmethod()
compile()
complex()
delattr()
dict()
dir()
divmod()
enumerate()
eval()
exec()
filter()
float()
format()
frozenset()
getattr()
globals()
hasattr()
hash()
help()
hex()
id()
input()
int()
isinstance()
issubclass()
iter()
len()
list()
locals()
map()
max()
memoryview()
min()
next()
object()
oct()
open()
ord()
pow()
print()
property()
range()
repr()
reversed()
round()
set()
setattr()
slice()
sorted()
staticmethod()
str()
sum()
super()
tuple()
type()
vars()
zip()
__import__()
print()
Screen рдкрд░ output рджिрдЦाрдиे рдХे рд▓िрдП:
print("Hello")
Multiple values:
print("Age:", 25)
Separator:
print("HTML", "CSS", "Python", sep=" | ")
New line control:
print("Hello", end=" ")
print("World")
input()
User рд╕े input рд▓ेрдиे рдХे рд▓िрдП:
name = input("Enter your name: ")
print(name)
Input рдХो integer рдоें рдмрджрд▓рдиा:
age = int(input("Enter age: "))
len()
Length рдкрддा рдХрд░рдиे рдХे рд▓िрдП:
len("Python")
List:
len([1, 2, 3])
type()
Object рдХा type рдкрддा рдХрд░рдиे рдХे рд▓िрдП:
type(25)
Output:
<class 'int'>
isinstance()
Check рдХрд░рдиे рдХे рд▓िрдП рдХि object рдХिрд╕ी type рдпा class рдХा instance рд╣ै рдпा рдирд╣ीं:
isinstance(10, int)
Output:
True
id()
Object рдХी identity рджेрдЦрдиे рдХे рд▓िрдП:
id(name)
dir()
рдХिрд╕ी object рдХे available attributes рдФрд░ methods рджेрдЦрдиे рдХे рд▓िрдП:
dir("Python")
help()
Python documentation/help рджेрдЦрдиे рдХे рд▓िрдП:
help(print)
Number Functions
abs()
Absolute value:
abs(-25)
Output:
25
round()
round(10.567)
pow()
pow(2, 3)
Output:
8
max()
max(10, 20, 5)
min()
min(10, 20, 5)
sum()
sum([10, 20, 30])
divmod()
divmod(10, 3)
Output:
(3, 1)
Number Conversion Functions
int("25")
float("10.5")
complex(2, 3)
bool(1)
Binary:
bin(10)
Octal:
oct(10)
Hexadecimal:
hex(10)
Character Functions
chr()
Unicode number рдХो character рдоें:
chr(65)
Output:
A
ord()
Character рдХो Unicode number рдоें:
ord("A")
Output:
65
Python Operators
Arithmetic Operators
+
-
*
/
%
**
//
Example:
a = 10
b = 3
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a % b)
print(a ** b)
print(a // b)
Assignment Operators
=
+=
-=
*=
/=
%=
**=
//=
&=
|=
^=
>>=
<<=
Example:
count = 10
count += 5
рдЕрдм:
15
Comparison Operators
==
!=
>
<
>=
<=
Example:
10 > 5
Output:
True
Logical Operators
and
or
not
Example:
age >= 18 and country == "India"
Identity Operators
is
is not
Example:
a is b
рдз्рдпाрди рд░рдЦें рдХि is рдФрд░ == рдХा рдХाрдо рдЕрд▓рдЧ рд╣ोрддा рд╣ै।
== values compare рдХрд░рддा рд╣ै, рдЬрдмрдХि is object identity check рдХрд░рддा рд╣ै।
Membership Operators
in
not in
Example:
"Py" in "Python"
Output:
True
Bitwise Operators
&
|
^
~
<<
>>
Example:
5 & 3
5 | 3
5 ^ 3
~5
5 << 1
5 >> 1
Python Conditions
if
age = 20
if age >= 18:
print("Adult")
if-else
if age >= 18:
print("Adult")
else:
print("Minor")
if-elif-else
marks = 75
if marks >= 90:
print("A")
elif marks >= 60:
print("B")
else:
print("C")
Conditional Expression
рдЫोрдЯे condition рдХे рд▓िрдП:
age = 20
result = "Adult" if age >= 18 else "Minor"
Python Match Statement
Modern Python рдоें pattern matching рдХे рд▓िрдП match рдЗрд╕्рддेрдоाрд▓ рдХिрдпा рдЬा рд╕рдХрддा рд╣ै।
day = 2
match day:
case 1:
print("Monday")
case 2:
print("Tuesday")
case _:
print("Unknown")
Python Loops
Python рдоें рдоुрдЦ्рдп loops:
forwhile
for Loop
for i in range(1, 6):
print(i)
while Loop
i = 1
while i <= 5:
print(i)
i += 1
break
Loop рдХो рд░ोрдХрдиे рдХे рд▓िрдП:
for i in range(10):
if i == 5:
break
print(i)
continue
Current iteration рдХो skip рдХрд░рдиे рдХे рд▓िрдП:
for i in range(5):
if i == 2:
continue
print(i)
pass
Empty block рдХे рд▓िрдП:
if True:
pass
range()
Numbers рдХी sequence рдмрдиाрдиे рдХे рд▓िрдП:
range(5)
range(1, 10)
range(1, 10, 2)
Python Lists
List рдоें multiple values store рдХी рдЬा рд╕рдХрддी рд╣ैं।
colors = ["Red", "Green", "Blue"]
List Mutable рд╣ोрддी рд╣ै, рдпाрдиी рдЗрд╕рдХी values рдмрджрд▓ी рдЬा рд╕рдХрддी рд╣ैं।
colors[0] = "Black"
List Methods
Python List рдХे important methods:
append()
clear()
copy()
count()
extend()
index()
insert()
pop()
remove()
reverse()
sort()
append()
End рдоें item рдЬोрдб़ें:
colors.append("Yellow")
extend()
Multiple items рдЬोрдб़ें:
colors.extend(["Pink", "White"])
insert()
Specific position рдкрд░ item:
colors.insert(1, "Black")
remove()
Value remove рдХрд░ें:
colors.remove("Red")
pop()
Last item remove рдФрд░ return рдХрд░ें:
colors.pop()
Specific index:
colors.pop(0)
clear()
рдкूрд░ी list рдЦाрд▓ी рдХрд░ें:
colors.clear()
copy()
List рдХी copy:
new_colors = colors.copy()
count()
рдХिрд╕ी value рдХी count:
colors.count("Red")
index()
Value рдХी position:
colors.index("Blue")
reverse()
List reverse:
colors.reverse()
sort()
Ascending:
numbers.sort()
Descending:
numbers.sort(reverse=True)
List Slicing
numbers[0:3]
numbers[:3]
numbers[2:]
numbers[::-1]
List Comprehension
Short рддрд░ीрдХे рд╕े list рдмрдиाрдиे рдХे рд▓िрдП:
squares = [x * x for x in range(10)]
Condition:
even = [x for x in range(20) if x % 2 == 0]
Python Tuples
Tuple List рдЬैрд╕ा рд╣ै рд▓ेрдХिрди generally immutable рд╣ोрддा рд╣ै।
colors = ("Red", "Green", "Blue")
Single-item tuple:
item = ("Python",)
Tuple methods:
count()
index()
Tuple Unpacking
name, age = ("Rahul", 20)
Python Sets
Set рдоें unique values рд╣ोрддी рд╣ैं।
numbers = {1, 2, 3, 3}
Duplicate values automatically рд╣рдЯ рдЬाрддी рд╣ैं।
Set Methods
Important Set methods:
add()
clear()
copy()
difference()
difference_update()
discard()
intersection()
intersection_update()
isdisjoint()
issubset()
issuperset()
pop()
remove()
symmetric_difference()
symmetric_difference_update()
union()
update()
add()
numbers.add(5)
remove()
numbers.remove(2)
discard()
numbers.discard(10)
discard() рдоें value рдоौрдЬूрдж рди рд╣ो рддो рд╕ाрдоाрди्рдпрддः error рдирд╣ीं рдЖрддा।
union()
рджो sets рдХो combine рдХрд░ें:
a.union(b)
рдпा:
a | b
intersection()
Common values:
a.intersection(b)
рдпा:
a & b
difference()
рдкрд╣рд▓े set рдоें рдоौрдЬूрдж рд▓ेрдХिрди рджूрд╕рд░े рдоें рдирд╣ीं:
a.difference(b)
рдпा:
a - b
symmetric_difference()
рджोрдиों sets рдХी non-common values:
a.symmetric_difference(b)
Python Dictionaries
Dictionary Key-Value pairs рдоें data store рдХрд░рддी рд╣ै।
student = {
"name": "Rahul",
"age": 20,
"city": "Delhi"
}
Value:
student["name"]
Safe access:
student.get("name")
Dictionary Methods
Important methods:
clear()
copy()
fromkeys()
get()
items()
keys()
pop()
popitem()
setdefault()
update()
values()
keys()
student.keys()
values()
student.values()
items()
student.items()
update()
student.update({"age": 21})
pop()
student.pop("age")
popitem()
Last inserted key-value pair рд╣рдЯाрдиे рдХे рд▓िрдП:
student.popitem()
Dictionary Comprehension
squares = {x: x*x for x in range(5)}
Nested Dictionary
students = {
"student1": {
"name": "Rahul",
"age": 20
},
"student2": {
"name": "Aman",
"age": 21
}
}
Python Strings рдХे Important Methods
String methods рдХी рдмрдб़ी list:
capitalize()
casefold()
center()
count()
encode()
endswith()
expandtabs()
find()
format()
format_map()
index()
isalnum()
isalpha()
isascii()
isdecimal()
isdigit()
isidentifier()
islower()
isnumeric()
isprintable()
isspace()
istitle()
isupper()
join()
ljust()
lower()
lstrip()
partition()
removeprefix()
removesuffix()
replace()
rfind()
rindex()
rjust()
rpartition()
rsplit()
rstrip()
split()
splitlines()
startswith()
strip()
swapcase()
title()
translate()
upper()
zfill()
lower()
text.lower()
upper()
text.upper()
capitalize()
text.capitalize()
title()
text.title()
swapcase()
text.swapcase()
strip()
text.strip()
lstrip()
text.lstrip()
rstrip()
text.rstrip()
replace()
text.replace("Python", "Java")
split()
String рдХो list рдоें:
"HTML CSS Python".split()
join()
List рдХो string рдоें:
" ".join(["HTML", "CSS", "Python"])
find()
text.find("Python")
startswith()
text.startswith("Py")
endswith()
text.endswith("on")
count()
text.count("a")
f-Strings
Python рдоें formatted text рдХे рд▓िрдП f-string рдмрд╣ुрдд useful рд╣ै।
name = "Rahul"
age = 20
print(f"My name is {name} and I am {age} years old.")
String Formatting
name = "Rahul"
print("Hello {}".format(name))
Escape Characters
рдХुрдЫ common escape sequences:
\n New Line
\t Tab
\\ Backslash
\' Single Quote
\" Double Quote
\b Backspace
\r Carriage Return
Python Functions
Function рдмрдиाрдиे рдХे рд▓िрдП:
def greet():
print("Hello")
Function call:
greet()
Function Parameters
def greet(name):
print("Hello", name)
greet("Rahul")
Return
def add(a, b):
return a + b
result = add(10, 20)
Default Arguments
def greet(name="Guest"):
print("Hello", name)
Keyword Arguments
greet(name="Rahul")
*args
Multiple positional arguments:
def total(*args):
return sum(args)
**kwargs
Multiple keyword arguments:
def info(**kwargs):
print(kwargs)
Lambda Function
square = lambda x: x * x
map()
рд╣рд░ item рдкрд░ function apply рдХрд░рдиे рдХे рд▓िрдП:
numbers = [1, 2, 3, 4]
result = list(map(lambda x: x * 2, numbers))
filter()
Condition рдХे рдЖрдзाрд░ рдкрд░ values filter рдХрд░ें:
numbers = [1, 2, 3, 4, 5]
result = list(filter(lambda x: x % 2 == 0, numbers))
reduce()
functools рд╕े:
from functools import reduce
result = reduce(lambda a, b: a + b, [1, 2, 3, 4])
zip()
рджो рдпा рдЬ्рдпाрджा sequences рдХो combine рдХрд░ें:
names = ["A", "B", "C"]
ages = [20, 21, 22]
result = zip(names, ages)
List:
list(zip(names, ages))
enumerate()
Index рдХे рд╕ाрде values:
names = ["Aman", "Ravi", "Rahul"]
for index, name in enumerate(names):
print(index, name)
sorted()
рдирдИ sorted list:
numbers = [5, 2, 8, 1]
result = sorted(numbers)
Descending:
sorted(numbers, reverse=True)
reversed()
Sequence рдХो reverse order рдоें iterate рдХрд░рдиे рдХे рд▓िрдП:
list(reversed(numbers))
any()
рдЕрдЧрд░ рдХोрдИ рднी value True рд╣ै:
any([False, False, True])
all()
рдЕрдЧрд░ рд╕рднी values True рд╣ैं:
all([True, True, True])
Python Iterators
Iterator рдмрдиाрдиे рдХे рд▓िрдП:
numbers = iter([1, 2, 3])
Next value:
next(numbers)
Python Generators
Generator yield рдХा рдЗрд╕्рддेрдоाрд▓ рдХрд░рддा рд╣ै।
def numbers():
for i in range(5):
yield i
Generator:
for number in numbers():
print(number)
Generators memory efficient рд╣ो рд╕рдХрддे рд╣ैं рдХ्рдпोंрдХि рд╡े values рдХो рдПрдХ рд╕ाрде рдмрдиाрдиे рдХे рдмрдЬाрдп рдЬрд░ूрд░рдд рдХे рдЕрдиुрд╕ाрд░ produce рдХрд░рддे рд╣ैं।
Generator Expression
squares = (x*x for x in range(10))
Python Scope
Python рдоें рдоुрдЦ्рдп scopes:
Local
Enclosing
Global
Built-in
рдЗрд╕े рдЕрдХ्рд╕рд░ LEGB Rule рдХрд╣ा рдЬाрддा рд╣ै।
global
Global variable рдХो function рдХे рдЕंрджрд░ modify рдХрд░рдиे рдХे рд▓िрдП:
count = 0
def update():
global count
count += 1
nonlocal
Nested function рдоें enclosing scope рдХी variable рдмрджрд▓рдиे рдХे рд▓िрдП:
def outer():
count = 0
def inner():
nonlocal count
count += 1
Python Modules
Python рдоें code рдХो рдЕрд▓рдЧ-рдЕрд▓рдЧ files/modules рдоें organize рдХिрдпा рдЬा рд╕рдХрддा рд╣ै।
Example:
import math
import
import math
print(math.sqrt(25))
from ... import
from math import sqrt
print(sqrt(25))
as
Alias рдмрдиाрдиे рдХे рд▓िрдП:
import numpy as np
Important Python Standard Library Modules
Python Standard Library рдоें рдмрд╣ुрдд рд╕ाрд░े useful modules рд╣ैं:
math
random
datetime
time
os
sys
json
re
statistics
decimal
fractions
pathlib
shutil
glob
subprocess
sqlite3
csv
collections
itertools
functools
operator
string
textwrap
logging
argparse
configparser
hashlib
secrets
typing
dataclasses
enum
abc
copy
pprint
traceback
unittest
doctest
math Module
import math
Useful functions/constants:
sqrt()
pow()
ceil()
floor()
factorial()
gcd()
lcm()
fabs()
isfinite()
isinf()
isnan()
log()
log10()
exp()
sin()
cos()
tan()
degrees()
radians()
pi
e
tau
inf
nan
Example:
math.sqrt(25)
random Module
Random values рдХे рд▓िрдП:
import random
Important functions:
random()
randint()
randrange()
choice()
choices()
sample()
shuffle()
uniform()
getrandbits()
Example:
random.randint(1, 100)
List рд╕े random item:
random.choice(["Red", "Blue", "Green"])
List shuffle:
random.shuffle(colors)
datetime Module
Date рдФрд░ Time рдХे рд▓िрдП:
from datetime import datetime, date, time, timedelta
Current Date-Time:
datetime.now()
Current Date:
date.today()
Date difference:
timedelta(days=7)
os Module
Operating System рд╕े related рдХाрдо:
import os
Useful functions:
getcwd()
chdir()
listdir()
mkdir()
makedirs()
remove()
rename()
rmdir()
walk()
environ
Current directory:
os.getcwd()
Files:
os.listdir()
pathlib
Modern file path handling рдХे рд▓िрдП:
from pathlib import Path
Example:
path = Path("data.txt")
Check:
path.exists()
Read:
path.read_text()
Write:
path.write_text("Hello Python")
File Handling
File open рдХрд░рдиे рдХे рд▓िрдП:
file = open("data.txt", "r")
File read:
data = file.read()
File close:
file.close()
рд▓ेрдХिрди рдмेрд╣рддрд░ рддрд░ीрдХा рд╣ै:
with open("data.txt", "r") as file:
data = file.read()
File Modes
r Read
w Write
a Append
x Create
b Binary
t Text
+ Read and Write
Examples:
open("data.txt", "r")
open("data.txt", "w")
open("data.txt", "a")
File Methods
Important methods:
read()
readline()
readlines()
write()
writelines()
seek()
tell()
flush()
close()
readable()
writable()
seekable()
JSON
Python рдоें JSON рдХे рд▓िрдП:
import json
Python object → JSON:
json.dumps(data)
JSON → Python object:
json.loads(data)
File рдоें JSON write:
json.dump(data, file)
File рд╕े JSON read:
json.load(file)
Regular Expressions
Regex рдХे рд▓िрдП:
import re
Important functions:
match()
search()
findall()
finditer()
split()
sub()
fullmatch()
escape()
compile()
Example:
import re
result = re.search("Python", "I love Python")
Python Exception Handling
Error рдХो handle рдХрд░рдиे рдХे рд▓िрдП:
try:
number = int(input("Enter number: "))
except ValueError:
print("Invalid number")
try-except-else-finally
try:
result = 10 / 2
except ZeroDivisionError:
print("Cannot divide by zero")
else:
print("Success")
finally:
print("Done")
Common Python Exceptions
Exception
ValueError
TypeError
NameError
IndexError
KeyError
AttributeError
ZeroDivisionError
FileNotFoundError
ImportError
ModuleNotFoundError
RuntimeError
OSError
PermissionError
OverflowError
NotImplementedError
StopIteration
raise
Custom error generate рдХрд░рдиे рдХे рд▓िрдП:
age = 15
if age < 18:
raise ValueError("Age must be 18 or above")
Custom Exception
class MyError(Exception):
pass
Python OOP
Python рдоें Object-Oriented Programming рдХे important concepts:
Class
Object
Attribute
Method
Constructor
Inheritance
Encapsulation
Polymorphism
Abstraction
Composition
Aggregation
Interface-like design
Class
class Student:
pass
Object
student = Student()
Constructor
class Student:
def __init__(self, name):
self.name = name
Object:
student = Student("Rahul")
Instance Method
class Student:
def greet(self):
print("Hello")
Class Variable
class Student:
school = "ABC School"
Instance Variable
class Student:
def __init__(self, name):
self.name = name
Inheritance
class Animal:
def sound(self):
print("Sound")
class Dog(Animal):
pass
Method Overriding
class Dog(Animal):
def sound(self):
print("Bark")
super()
Parent class рдХे methods/constructor рдХो access рдХрд░рдиे рдХे рд▓िрдП:
class Dog(Animal):
def __init__(self):
super().__init__()
Encapsulation
Python рдоें _name рдФрд░ __name рдЬैрд╕ी naming conventions/access mechanisms рдЗрд╕्рддेрдоाрд▓ рдХिрдП рдЬाрддे рд╣ैं।
class Student:
def __init__(self):
self.__name = "Rahul"
Property
class Student:
def __init__(self):
self._name = ""
@property
def name(self):
return self._name
Static Method
class Math:
@staticmethod
def add(a, b):
return a + b
Class Method
class Student:
school = "ABC"
@classmethod
def change_school(cls, name):
cls.school = name
Abstract Classes
abc module рдХा рдЗрд╕्рддेрдоाрд▓ рдХिрдпा рдЬा рд╕рдХрддा рд╣ै:
from abc import ABC, abstractmethod
class Animal(ABC):
@abstractmethod
def sound(self):
pass
Dataclasses
Simple data-holding classes рдХे рд▓िрдП:
from dataclasses import dataclass
@dataclass
class Student:
name: str
age: int
Python Decorators
Decorator function рдХे behavior рдХो modify рдпा wrap рдХрд░рдиे рдоें рдорджрдж рдХрд░рддा рд╣ै।
def decorator(func):
def wrapper():
print("Before")
func()
print("After")
return wrapper
Use:
@decorator
def hello():
print("Hello")
functools Module
Useful tools:
reduce()
partial()
lru_cache()
cache()
wraps()
total_ordering()
singledispatch()
itertools Module
Iteration рдХे рд▓िрдП рдмрд╣ुрдд useful module:
import itertools
Important functions:
count()
cycle()
repeat()
chain()
compress()
dropwhile()
takewhile()
filterfalse()
islice()
starmap()
accumulate()
product()
permutations()
combinations()
combinations_with_replacement()
groupby()
pairwise()
collections Module
Useful data structures:
Counter
defaultdict
deque
namedtuple
OrderedDict
ChainMap
UserDict
UserList
UserString
Counter
Items рдХी frequency:
from collections import Counter
count = Counter(["A", "B", "A", "C", "A"])
defaultdict
Default value рдХे рд╕ाрде dictionary:
from collections import defaultdict
data = defaultdict(list)
deque
Fast double-ended queue:
from collections import deque
queue = deque()
queue.append("A")
queue.appendleft("B")
Useful methods:
append()
appendleft()
clear()
copy()
count()
extend()
extendleft()
index()
insert()
pop()
popleft()
remove()
reverse()
rotate()
Python statistics
Statistics рдХे рд▓िрдП:
import statistics
Important functions:
mean()
fmean()
geometric_mean()
harmonic_mean()
median()
median_low()
median_high()
median_grouped()
mode()
multimode()
quantiles()
variance()
pvariance()
stdev()
pstdev()
covariance()
correlation()
linear_regression()
Python decimal
Precise decimal calculations рдХे рд▓िрдП:
from decimal import Decimal
Example:
price = Decimal("10.50")
Python fractions
Fractions рдХे рд▓िрдП:
from fractions import Fraction
value = Fraction(1, 3)
Python sqlite3
Local SQLite database рдХे рд▓िрдП:
import sqlite3
Connection:
conn = sqlite3.connect("school.db")
Cursor:
cursor = conn.cursor()
Query:
cursor.execute("SELECT * FROM students")
Python CSV
CSV files рдХे рд▓िрдП:
import csv
CSV рдкрдв़рдиा:
with open("data.csv") as file:
reader = csv.reader(file)
for row in reader:
print(row)
Python Environment
Python рдоें environment management рдХे рд▓िрдП virtual environment рдмрд╣ुрдд useful рд╣ै।
Create:
python -m venv venv
Activate рдХрд░рдиे рдХा рддрд░ीрдХा operating system рдкрд░ depend рдХрд░рддा рд╣ै।
Package install:
pip install package_name
Installed packages:
pip list
Package information:
pip show package_name
Packages update:
python -m pip install --upgrade package_name
Python pip
Common commands:
pip install
pip uninstall
pip list
pip show
pip freeze
pip check
pip download
pip wheel
Requirements file:
pip freeze > requirements.txt
Install:
pip install -r requirements.txt
Python Import Concepts
import module
from module import function
import module as alias
from module import *
рдЖрдорддौрд░ рдкрд░ explicit imports рд░рдЦрдиा рдЬ्рдпाрджा readable рд╣ोрддा рд╣ै।
__name__
Python files рдоें common pattern:
if __name__ == "__main__":
main()
рдЗрд╕рдХा рдЗрд╕्рддेрдоाрд▓ рдпрд╣ рддрдп рдХрд░рдиे рдоें рдорджрдж рдХрд░рддा рд╣ै рдХि file рд╕ीрдзे run рд╣ुрдИ рд╣ै рдпा module рдХे рд░ूрдк рдоें import рд╣ुрдИ рд╣ै।
Python Special Methods
Python рдоें рдХрдИ special/dunder methods рд╣ोрддे рд╣ैं:
__init__()
__str__()
__repr__()
__len__()
__iter__()
__next__()
__getitem__()
__setitem__()
__delitem__()
__contains__()
__call__()
__eq__()
__lt__()
__le__()
__gt__()
__ge__()
__add__()
__sub__()
__mul__()
__truediv__()
__floordiv__()
__mod__()
__pow__()
__enter__()
__exit__()
Example:
class Student:
def __str__(self):
return "Student Object"
Context Manager
File handling рдоें:
with open("data.txt") as file:
print(file.read())
рдпрд╣ resource рдХो рд╕рд╣ी рддрд░ीрдХे рд╕े manage рдХрд░рдиे рдоें рдорджрдж рдХрд░рддा рд╣ै।
Custom context manager рдоें:
__enter__()
__exit__()
рдХा рдЗрд╕्рддेрдоाрд▓ рдХिрдпा рдЬा рд╕рдХрддा рд╣ै।
Python Type Hints
Type hints code рдХो рдЬ्рдпाрджा readable рдФрд░ maintainable рдмрдиाрдиे рдоें рдорджрдж рдХрд░ рд╕рдХрддे рд╣ैं।
def add(a: int, b: int) -> int:
return a + b
Complex types:
from typing import List
numbers: List[int] = [1, 2, 3]
Modern Python рдоें built-in generic syntax рднी рдЗрд╕्рддेрдоाрд▓ рдХिрдпा рдЬा рд╕рдХрддा рд╣ै:
numbers: list[int] = [1, 2, 3]
Python Useful Built-in Concepts
Mutable
Immutable
Iterable
Iterator
Generator
Sequence
Mapping
Hashable
Callable
Context Manager
Namespace
Scope
Decorator
Comprehension
Lambda
Closure
Recursion
Duck Typing
Type Hinting
Pattern Matching
Mutable vs Immutable
Mutable
рдЗрдирдХी values рдмрджрд▓ рд╕рдХрддी рд╣ैं:
list
dict
set
bytearray
Immutable
рдЗрдирдХी value directly modify рдирд╣ीं рдХी рдЬा рд╕рдХрддी:
int
float
bool
str
tuple
frozenset
bytes
Python Recursion
рдЬрдм function рдЦुрдж рдХो call рдХрд░рддा рд╣ै рддो рдЙрд╕े recursion рдХрд╣рддे рд╣ैं।
def countdown(n):
if n == 0:
return
print(n)
countdown(n - 1)
Python Lambda
add = lambda a, b: a + b
print(add(10, 20))
Lambda рдЫोрдЯे functions рдХे рд▓िрдП useful рд╣ै।
Python Comprehensions
List Comprehension
[x * 2 for x in range(5)]
Set Comprehension
{x * 2 for x in range(5)}
Dictionary Comprehension
{x: x*x for x in range(5)}
Generator Expression
(x * 2 for x in range(5))
Python Sorting
Basic:
numbers.sort()
рдирдИ list:
sorted(numbers)
Reverse:
sorted(numbers, reverse=True)
Key рдХे рд╕ाрде:
students = [
{"name": "A", "age": 25},
{"name": "B", "age": 20}
]
sorted(students, key=lambda x: x["age"])
Python Searching
List рдоें:
if "Python" in languages:
print("Found")
Dictionary рдоें:
if "name" in student:
print("Found")
String рдоें:
if "Py" in text:
print("Found")
Python open() Function
open("file.txt", "r")
Common arguments:
file
mode
buffering
encoding
errors
newline
closefd
opener
UTF-8 text:
with open("data.txt", "r", encoding="utf-8") as file:
data = file.read()
Python eval() рдФрд░ exec()
eval() expression evaluate рдХрд░ рд╕рдХрддा рд╣ै:
result = eval("10 + 20")
exec() Python code execute рдХрд░ рд╕рдХрддा рд╣ै:
exec("x = 10")
⚠️ User-provided untrusted input рдХे рд╕ाрде рдЗрдирдХा рдЗрд╕्рддेрдоाрд▓ рдХрд░рдиा dangerous рд╣ो рд╕рдХрддा рд╣ै।
Python compile()
Code рдХो compiled code object рдоें рдмрджрд▓рдиे рдХे рд▓िрдП:
code = compile("x = 10", "<string>", "exec")
Python hash()
Hash value:
hash("Python")
Python callable()
Check рдХрд░ें рдХि object callable рд╣ै рдпा рдирд╣ीं:
callable(print)
Python getattr()
Object рдХा attribute dynamic рддрд░ीрдХे рд╕े:
getattr(student, "name")
Python setattr()
Attribute set рдХрд░рдиे рдХे рд▓िрдП:
setattr(student, "age", 20)
Python hasattr()
Check:
hasattr(student, "name")
Python delattr()
Attribute delete:
delattr(student, "age")
Python repr()
Object рдХा developer-oriented representation:
repr("Python")
Python format()
Value format рдХрд░рдиे рдХे рд▓िрдП:
format(10, "04")
Python ascii()
Object рдХा ASCII-oriented representation:
ascii("Python")
Python object()
Base object:
obj = object()
Python super()
Parent class рд╕े functionality access рдХрд░рдиे рдХे рд▓िрдП:
super().method()
Python property()
Attribute access рдХो controlled рддрд░ीрдХे рд╕े manage рдХрд░рдиे рдХे рд▓िрдП:
property(getter, setter)
Python staticmethod()
Static method рдмрдиाрдиे рдХे рд▓िрдП:
staticmethod(function)
рдЖрдорддौрд░ рдкрд░ decorator syntax рдЬ्рдпाрджा readable рд╣ै:
@staticmethod
def add(a, b):
return a + b
Python classmethod()
Class method рдХे рд▓िрдП:
@classmethod
def create(cls):
return cls()
Python slice()
Slice object рдмрдиाрдиे рдХे рд▓िрдП:
s = slice(0, 5)
text[s]
Python memoryview()
Buffer-oriented data рдХे рд╕ाрде рдХाрдо рдХрд░рдиे рдХे рд▓िрдП:
data = bytearray("Python", "utf-8")
view = memoryview(data)
Python bytes()
Immutable bytes:
data = bytes("Python", "utf-8")
Python bytearray()
Mutable byte sequence:
data = bytearray(b"Python")
Python frozenset()
Immutable set:
numbers = frozenset([1, 2, 3])
Python enumerate()
Index рдФрд░ value рд╕ाрде рдоें:
for index, value in enumerate(["A", "B", "C"], start=1):
print(index, value)
Python zip()
names = ["A", "B"]
ages = [20, 21]
for name, age in zip(names, ages):
print(name, age)
Python Debugging
Debugging рдХे рд▓िрдП:
breakpoint()
рдЖрдк IDE debugger рднी рдЗрд╕्рддेрдоाрд▓ рдХрд░ рд╕рдХрддे рд╣ैं।
Basic debugging рдоें:
print(variable)
рдФрд░:
type(variable)
рдЬैрд╕े techniques рднी useful рд╣ैं।
Python Logging
Production applications рдоें print() рдХी рдЬрдЧрд╣ рдЕрдХ्рд╕рд░ logging рдЬ्рдпाрджा useful рд╣ोрддी рд╣ै।
import logging
logging.basicConfig(level=logging.INFO)
logging.info("Application started")
logging.warning("Something may be wrong")
logging.error("An error occurred")
Common levels:
DEBUG
INFO
WARNING
ERROR
CRITICAL
Python Testing
Python рдоें built-in unittest module available рд╣ै।
import unittest
class TestMath(unittest.TestCase):
def test_add(self):
self.assertEqual(2 + 3, 5)
Common assertions:
assertEqual()
assertNotEqual()
assertTrue()
assertFalse()
assertIs()
assertIsNone()
assertIn()
assertNotIn()
assertRaises()
Python Security Basics
Python application рдмрдиाрддे рд╕рдордп:
User input validate рдХрд░ें।
Password рдХो plain text рдоें store рди рдХрд░ें।
Secrets рдХो source code рдоें hard-code рди рдХрд░ें।
Environment variables рдХा рдЗрд╕्рддेрдоाрд▓ рдХрд░ें।
SQL queries рдоें parameterized queries рдЗрд╕्рддेрдоाрд▓ рдХрд░ें।
Untrusted input рдХे рд╕ाрде
eval()/exec()avoid рдХрд░ें।File upload рдоें type рдФрд░ size validate рдХрд░ें।
Dependencies рдХो updated рд░рдЦें।
HTTPS рдХा рдЗрд╕्рддेрдоाрд▓ рдХрд░ें।
Python рдоें Environment Variables
import os
api_key = os.getenv("API_KEY")
Sensitive keys рдХो code рдоें рд╕ीрдзे рд▓िрдЦрдиे рдХे рдмрдЬाрдп environment configuration рдХा рдЗрд╕्рддेрдоाрд▓ рдХрд░рдиा рдмेрд╣рддрд░ рд╣ै।
Python Project Structure
рдПрдХ simple project:
my_project/
│
├── main.py
├── requirements.txt
├── README.md
│
├── app/
│ ├── __init__.py
│ ├── models.py
│ └── utils.py
│
└── tests/
└── test_app.py
рдмрдб़े projects рдоें structure project рдХी рдЬрд░ूрд░рдд рдХे рдЕрдиुрд╕ाрд░ рдЕрд▓рдЧ рд╣ो рд╕рдХрддा рд╣ै।
Python Naming Conventions
Variable
user_name = "Rahul"
Function
def calculate_total():
pass
Class
class StudentProfile:
pass
Constant
MAX_USERS = 100
Python рдоें naming conventions readability improve рдХрд░рддी рд╣ैं।
Python Useful Methods Quick List
String
lower()
upper()
capitalize()
title()
strip()
split()
join()
replace()
find()
count()
startswith()
endswith()
List
append()
extend()
insert()
remove()
pop()
clear()
copy()
count()
index()
reverse()
sort()
Tuple
count()
index()
Set
add()
remove()
discard()
pop()
clear()
union()
intersection()
difference()
symmetric_difference()
update()
Dictionary
get()
keys()
values()
items()
update()
pop()
popitem()
clear()
copy()
setdefault()
fromkeys()
Python Functional Tools Quick List
map()
filter()
reduce()
zip()
enumerate()
sorted()
reversed()
any()
all()
iter()
next()
Python File Tools Quick List
open()
read()
readline()
readlines()
write()
writelines()
seek()
tell()
flush()
close()
Python Date-Time Quick List
datetime.now()
date.today()
timedelta()
strftime()
strptime()
Example:
from datetime import datetime
now = datetime.now()
print(now.strftime("%d-%m-%Y"))
Python Regular Expression Quick List
re.match()
re.search()
re.fullmatch()
re.findall()
re.finditer()
re.split()
re.sub()
re.compile()
re.escape()
Python Collections Quick List
Counter
defaultdict
deque
namedtuple
OrderedDict
ChainMap
Python Itertools Quick List
count()
cycle()
repeat()
chain()
compress()
dropwhile()
takewhile()
filterfalse()
islice()
starmap()
accumulate()
product()
permutations()
combinations()
groupby()
pairwise()
Python OOP Quick Reference
| Concept | Meaning |
|---|---|
| Class | Object рдХा blueprint |
| Object | Class рдХा instance |
| Attribute | Object/Class рдХी data |
| Method | Class рдХे рдЕंрджрд░ function |
| Constructor | Object initialization |
| Inheritance | Parent рд╕े features рд▓ेрдиा |
| Encapsulation | Data/behavior рдХो organize рдХрд░рдиा |
| Polymorphism | Same interface, different behavior |
| Abstraction | рдЬрд░ूрд░ी details expose рдХрд░рдиा |
self | Current instance |
cls | Current class |
super() | Parent implementation access |
Python Keywords
Python рдоें рдХрдИ reserved keywords рд╣ैं:
False
None
True
and
as
assert
async
await
break
case
class
continue
def
del
elif
else
except
finally
for
from
global
if
import
in
is
lambda
match
nonlocal
not
or
pass
raise
return
try
while
with
yield
Python version рдХे рдЕрдиुрд╕ाрд░ available keywords рдоें рдмрджрд▓ाрд╡ рд╣ो рд╕рдХрддा рд╣ै।
Python Quick Cheat Sheet
| Topic | Important Things |
|---|---|
| Output | print() |
| Input | input() |
| Variables | name = "Rahul" |
| Types | str, int, float, bool |
| Collections | list, tuple, set, dict |
| Conditions | if, elif, else |
| Pattern Matching | match, case |
| Loops | for, while |
| Functions | def, return |
| Lambda | lambda |
| Comprehension | List, Set, Dict |
| Strings | split(), join(), replace() |
| Lists | append(), pop(), sort() |
| Sets | add(), union(), intersection() |
| Dictionary | get(), keys(), values() |
| Files | open(), read(), write() |
| JSON | json.dumps(), json.loads() |
| Errors | try, except, finally |
| Modules | import |
| OOP | Class, Object, Inheritance |
| Date-Time | datetime |
| Regex | re |
| Iteration | iter(), next() |
| Functional | map(), filter(), reduce() |
| Debugging | breakpoint() |
| Testing | unittest |
| Environment | venv, pip |
ЁЯТб рдоेрд░ी рд╕рд▓ाрд╣
рдЕрдЧрд░ рдЖрдк Python Beginner рд╣ैं, рддो рдПрдХ рд╕ाрде 500+ Functions рдпाрдж рдХрд░рдиे рдХी рдХोрд╢िрд╢ рдмिрд▓्рдХुрд▓ рди рдХрд░ें।
Python рд╕ीрдЦрдиे рдХे рд▓िрдП рдпрд╣ order follow рдХрд░ें:
Python Basics
↓
Variables
↓
Data Types
↓
Operators
↓
if-else
↓
Loops
↓
Strings
↓
Lists
↓
Tuples
↓
Sets
↓
Dictionaries
↓
Functions
↓
Comprehensions
↓
Modules
↓
File Handling
↓
Exception Handling
↓
OOP
↓
JSON & APIs
↓
Libraries
↓
Real Projects
рдЗрд╕ рддрд░ीрдХे рд╕े рд╕ीрдЦрдиे рдкрд░ concepts рдПрдХ-рджूрд╕рд░े рд╕े connect рд╣ोрддे рдЬाрдПंрдЧे।
⚠️ Note
Python рдХे рдЕрд▓рдЧ-рдЕрд▓рдЧ versions рдоें рдХुрдЫ features, modules рдпा behaviors рдмрджрд▓ рд╕рдХрддे рд╣ैं। рдЗрд╕рд▓िрдП рдкुрд░ाрдиे tutorials рд╕े рдоिрд▓े code рдХो рдЕрдкрдиे current Python version рдоें test рдХрд░рдиा рдЕрдЪ्рдЫा рд░рд╣рддा рд╣ै।
рдЗрд╕ी рддрд░рд╣ third-party libraries рдХे functions рдФрд░ methods Python Standard Library рд╕े рдЕрд▓рдЧ рд╣ोрддे рд╣ैं рдФрд░ рдЙрдирдХे versions рдХे рдЕрдиुрд╕ाрд░ рдмрджрд▓ рд╕рдХрддे рд╣ैं।
Python рдоें Beginner рдХौрди-рд╕े Projects рдмрдиा рд╕рдХрддा рд╣ै?
Practice рдХे рд▓िрдП рдпे projects рдХाрдлी рдЕрдЪ्рдЫे рд╣ैं:
| Project | рдХ्рдпा рд╕ीрдЦेंрдЧे |
|---|---|
| Calculator | Variables, Operators |
| Number Guessing Game | Conditions, Loops |
| To-Do List | Lists, Functions |
| Quiz App | Conditions, Dictionaries |
| Password Generator | Strings, Random |
| Contact Book | Dictionary, File Handling |
| Expense Tracker | Files, Lists |
| Student Management | OOP, Files |
| Weather App | APIs, JSON |
| URL Shortener | Web, Database |
| Blog | Web Development, Database |
| Login System | Forms, Hashing |
| File Organizer | os, pathlib, Automation |
| CSV Analyzer | CSV, Data Processing |
| Notes App | CRUD, Files/Database |
ЁЯТб Pro Tip
Python рдоें рд╣рд░ Function рдХो рдпाрдж рдХрд░рдиे рдХी рдЬрд░ूрд░рдд рдирд╣ीं рд╣ै।
рдЖрдкрдХो рдпрд╣ рдкрддा рд╣ोрдиा рдЬ्рдпाрджा рдЬрд░ूрд░ी рд╣ै рдХि рдХिрд╕ рдХाрдо рдХे рд▓िрдП рдХौрди-рд╕ा Function рдпा Method рдЗрд╕्рддेрдоाрд▓ рдХрд░рдиा рд╣ै।
рдЙрджाрд╣рд░рдг:
Length рдЪाрд╣िрдП →
len()Type рдЪाрд╣िрдП →
type()Input рдЪाрд╣िрдП →
input()Output рдЪाрд╣िрдП →
print()Maximum value →
max()Minimum value →
min()Total рдЪाрд╣िрдП →
sum()List рдоें item рдЬोрдб़рдиा рд╣ै →
append()List sort рдХрд░рдиी рд╣ै →
sort()Text рдмрджрд▓рдиा рд╣ै →
replace()Text split рдХрд░рдиा рд╣ै →
split()Text рдЬोрдб़рдиा рд╣ै →
join()Dictionary value рдЪाрд╣िрдП →
get()JSON рдмрдиाрдиा рд╣ै →
json.dumps()JSON рдкрдв़рдиा рд╣ै →
json.loads()File рдЦोрд▓рдиी рд╣ै →
open()Date рдЪाрд╣िрдП →
datetimeRandom value рдЪाрд╣िрдП →
randomRegular Expression рдЪाрд╣िрдП →
re
Practice рдХे рд╕ाрде рдпे Functions naturally рдпाрдж рд╣ोрдиे рд▓рдЧेंрдЧे।
Python рд╕ीрдЦрдиे рдХा рд╕рдмрд╕े рдЕрдЪ्рдЫा рддрд░ीрдХा
рдЕрдЧрд░ рдЖрдк рдмिрд▓्рдХुрд▓ Beginner рд╣ैं рддो рдкрд╣рд▓े рдЫोрдЯे programs рдмрдиाрдЗрдП।
Example:
name = input("Enter your name: ")
print(f"Hello {name}!")
рдлिрд░ Calculator:
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
рдЗрд╕рдХे рдмाрдж рдзीрд░े-рдзीрд░े:
Calculator
↓
Quiz App
↓
Number Guessing Game
↓
To-Do App
↓
Contact Book
↓
File Organizer
↓
API Project
↓
Database Project
↓
Web Application
рдХी рддрд░рдл рдЬाрдПँ।
Conclusion
Python рдПрдХ powerful рдФрд░ beginner-friendly programming language рд╣ै рдЬिрд╕рдХा рдЗрд╕्рддेрдоाрд▓ рдЫोрдЯे scripts рд╕े рд▓ेрдХрд░ рдмрдб़े software projects рдФрд░ data applications рддрдХ рдХिрдпा рдЬा рд╕рдХрддा рд╣ै।
рдЗрд╕ Python Complete Cheat Sheet рдоें рд╣рдордиे Python рдХे important:
Functions, Methods, Variables, Data Types, Operators, Conditions, Loops, Strings, Lists, Tuples, Sets, Dictionaries, Functions, Lambda, Comprehensions, Modules, File Handling, JSON, Regular Expressions, Exceptions, OOP, Decorators, Generators, Iterators, Collections, Itertools, Date-Time, Debugging, Testing рдФрд░ рдХрдИ рджूрд╕рд░े Concepts рдХो рдЖрд╕ाрди рднाрд╖ा рдоें рд╕рдордЭा।
рд▓ेрдХिрди рдпाрдж рд░рдЦें—Cheat Sheet рдкрдв़рдиा рдФрд░ Programming рд╕ीрдЦрдиा рджो рдЕрд▓рдЧ рдЪीрдЬें рд╣ैं।
Programming рд╕ीрдЦрдиे рдХे рд▓िрдП рдЖрдкрдХो рдЦुрдж Code рд▓िрдЦрдиा рдкрдб़ेрдЧा।
рд╕рдмрд╕े simple formula рдпाрдж рд░рдЦें:
Code рд▓िрдЦिрдП → Run рдХीрдЬिрдП → Error рджेрдЦिрдП → Error рд╕рдордЭिрдП → Fix рдХीрдЬिрдП → рдлिрд░ Practice рдХीрдЬिрдП। ЁЯЪА
рдЗрд╕ी рддрд░рд╣ рд▓рдЧाрддाрд░ practice рдХрд░рддे рд░рд╣рдиे рдкрд░ Python рдзीрд░े-рдзीрд░े рдЖрд╕ाрди рд▓рдЧрдиे рд▓рдЧेрдЧी।
FAQs
1. Python рдХ्рдпा рд╣ै?
Python рдПрдХ high-level, general-purpose programming language рд╣ै рдЬिрд╕рдХा рдЗрд╕्рддेрдоाрд▓ Web Development, Data Science, AI, Automation рдФрд░ рдХрдИ рджूрд╕рд░े рдХ्рд╖ेрдд्рд░ों рдоें рдХिрдпा рдЬाрддा рд╣ै।
2. рдХ्рдпा Python Beginners рдХे рд▓िрдП рдЕрдЪ्рдЫी рд╣ै?
рд╣ाँ। Python рдХा syntax relatively simple рдФрд░ readable рд╣ै, рдЗрд╕рд▓िрдП programming рд╢ुрд░ू рдХрд░рдиे рд╡ाрд▓े рд▓ोрдЧों рдХे рд▓िрдП рдпрд╣ рдПрдХ popular choice рд╣ै।
3. Python рд╕ीрдЦрдиे рд╕े рдкрд╣рд▓े рдХ्рдпा рдЖрдиा рдЪाрд╣िрдП?
Basic computer knowledge helpful рд╣ै। Programming рд╢ुрд░ू рдХрд░рдиे рдХे рд▓िрдП рдХिрд╕ी рджूрд╕рд░ी programming language рдХा expert рд╣ोрдиा рдЬрд░ूрд░ी рдирд╣ीं рд╣ै।
4. Python рдоें Variable рдХैрд╕े рдмрдиाрддे рд╣ैं?
Python рдоें рд╕ीрдзे value assign рдХрд░рдХे variable рдмрдиाрдпा рдЬाрддा рд╣ै:
name = "Rahul"
age = 20
5. Python рдоें print() рдХा рдХ्рдпा рдХाрдо рд╣ै?
print() рдХा рдЗрд╕्рддेрдоाрд▓ output рдХो display рдХрд░рдиे рдХे рд▓िрдП рдХिрдпा рдЬाрддा рд╣ै।
print("Hello Python")
6. Python рдоें List рдФрд░ Tuple рдоें рдХ्рдпा рдЕंрддрд░ рд╣ै?
List generally mutable рд╣ोрддी рд╣ै, рдЬрдмрдХि Tuple immutable рд╣ोрддी рд╣ै।
my_list = [1, 2, 3]
my_tuple = (1, 2, 3)
7. Python рдоें Dictionary рдХ्рдпा рд╣ोрддी рд╣ै?
Dictionary data рдХो key-value pairs рдоें store рдХрд░рддी рд╣ै।
student = {
"name": "Rahul",
"age": 20
}
8. Python рдоें Function рдХैрд╕े рдмрдиाрддे рд╣ैं?
def keyword рдХा рдЗрд╕्рддेрдоाрд▓ рдХрд░рдХे:
def greet():
print("Hello")
9. Python рдоें lambda рдХ्рдпा рд╣ै?
Lambda рдПрдХ рдЫोрдЯा anonymous function рдмрдиाрдиे рдХा рддрд░ीрдХा рд╣ै।
square = lambda x: x * x
10. Python рдоें for Loop рдХा рдХ्рдпा рдХाрдо рд╣ै?
for loop рдХा рдЗрд╕्рддेрдоाрд▓ рдХिрд╕ी iterable рдХे items рдкрд░ рдмाрд░-рдмाрд░ code execute рдХрд░рдиे рдХे рд▓िрдП рдХिрдпा рдЬाрддा рд╣ै।
for i in range(5):
print(i)
11. Python рдоें try-except рдХ्рдпों рдЗрд╕्рддेрдоाрд▓ рдХрд░рддे рд╣ैं?
Runtime errors рдХो handle рдХрд░рдиे рдХे рд▓िрдП:
try:
x = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
12. Python рдоें OOP рдХ्рдпा рд╣ै?
OOP рдпाрдиी Object-Oriented Programming। рдЗрд╕рдоें Class рдФрд░ Object рдЬैрд╕े concepts рдХा рдЗрд╕्рддेрдоाрд▓ рдХрд░рдХे applications рдХो organize рдХिрдпा рдЬाрддा рд╣ै।
13. Python рдоें Module рдХ्рдпा рд╣ोрддा рд╣ै?
Python file рдЬिрд╕рдоें reusable code, functions, classes рдпा variables рд╣ो рд╕рдХрддे рд╣ैं, рдЙрд╕े module рдХे рд░ूрдк рдоें import рдХिрдпा рдЬा рд╕рдХрддा рд╣ै।
import math
14. Python рдоें pip рдХ्рдпा рд╣ै?
pip Python packages рдХो install рдФрд░ manage рдХрд░рдиे рдХे рд▓िрдП commonly used package-management tool рд╣ै।
pip install requests
15. Python рд╕ीрдЦрдиे рдХा рд╕рдмрд╕े рдЕрдЪ्рдЫा рддрд░ीрдХा рдХ्рдпा рд╣ै?
рдкрд╣рд▓े Basics рд╕ीрдЦें рдФрд░ рдЙрд╕рдХे рдмाрдж рдЫोрдЯे-рдЫोрдЯे projects рдмрдиाрдПं। рд╕िрд░्рдл tutorials рджेрдЦрдиे рдХे рдмрдЬाрдп рд░ोрдЬ рдеोрдб़ा Code рд▓िрдЦрдиा рдЬ्рдпाрджा effective рд╣ै।
Python рд╕ीрдЦрдиे рдХा рд╕рдмрд╕े рдЕрдЪ्рдЫा formula рд╣ै:
Learn → Code → Run → Error → Fix → Practice → Project. ЁЯРНЁЯЪА
ЁЯОм Need help? Click the button below to watch the complete step-by-step video guide tutorial!
ЁЯУ║ Watch Full Video Guide