1.
Variables
Variable vaneko data store garne ek 'container' or 'dabba' jastai ho. Tapaile kunai value
(number, text) lai ek naam dinuhuncha ra pachi tyo naam use garera tyo value chalauna
saknuhuncha.
Key Points/Tips:
• Variable ko naam letter or underscore (_) bata suru huna parcha. Number bata suru garna
mildaina.
• Variable names are case-sensitive (age ra Age दइ
ु टा फरक variable hun).
• Naam meaningful rakham, jastai user_name or total_price. x, y, z jasto naam narakham
unless necessary.
Common Mistakes:
• Keywords (jastai if, for, class) lai variable naam banaune. Yo garna mildaina.
• Naam ko bich ma space dine (my name = "Ram"). Yesko satta underscore use garnus
(my_name = "Ram").
Interview Notes:
• Dynamic Typing: Python ma variable ko type (e.g., number, string) declare garna pardaina.
Python aafai bujhcha. x = 10 (integer), pachi x = "hello" (string) garna milcha. Yesailai
dynamic typing vanincha.
2. Type Casting
Type casting vaneko euta data type lai arko data type ma convert garne process ho. Jastai, text
("10") lai number (10) ma badalne.
Key Points/Tips:
• int(): Number (integer) ma convert garcha.
• float(): Decimal number ma convert garcha.
• str(): String (text) ma convert garcha.
• bool(): Boolean (True/False) ma convert garcha.
Common Mistakes:
• Number ma convert garna namilne string lai int() ma halne. int("hello") le error dincha.
nterview Notes:
• Sodna sakcha: "User input sadhai string huncha, teslai number ma calculation garna k
garnu parcha?" Answer: int() or float() use garera type casting garnu parcha.
3. User Input
User sanga terminal ma kei kura magna input() function ko prayog garincha. Yesle user le type
gareko kura lai string ko rup ma dincha.
Key Points/Tips:
• input() le return garne value sadhai string huncha, number type gare pani.
• User lai k input garne vanera prompt (message) dina input() bhitra message lekhna milcha.
Common Mistakes:
• Input liyera sidhai math operation garna khojne. age = input("Enter age: ") ra age + 5 garda
error auncha. Correct tarika int(age) + 5 ho.
Interview Notes:
• input() is a blocking function. Yesko matlab, user le kei type garera Enter nadabaesamma
program aghi badhdaina.
3. Arithmetic & Math
Neplingsh Explanation: Python ma simple calculator jastai jod, ghatau, gunan, ra bhag garna
sakincha.
Operators:
• + (Jod / Addition)
• - (Ghatau / Subtraction)
• * (Gunan / Multiplication)
• / (Bhag / Division) - Always returns a float (e.g., 10 / 2 is 5.0).
• // (Floor Division) - Point pachadi ko value hataidincha (e.g., 10 // 3 is 3).
• % (Modulus) - Remainder (sesh) dincha (e.g., 10 % 3 is 1).
• ** (Exponent) - Power (e.g., 2 ** 3 is 2^3=8).
Key Points/Tips:
• Complex math operations ko lagi, math module import garnu parcha. import math
[Link](16) le 4.0 dincha.
Interview Notes:
• Difference between / and // sodna sakcha. / le float division garcha, // le integer division
(floor) garcha.
5. String Methods, Indexing & Formatting
String vaneko text ho. Yesma kaam garna dherai built-in functions (methods) hunchan.
• Indexing: String ko kunai euta character access garne. Indexing 0 bata suru huncha.
• Slicing: String ko ek tukra (part) nikalne.
• Methods: String lai change or check garne functions.
• Formatting: String bhitra variables ko value halne.
Key Points/Tips:
• Strings are immutable. Yesko matlab, my_string[0] = 'h' garna mildaina. Original string
change hudaina. Methods le naya string return garcha.
• 'saagar' ra "saagar" ma kei farak chaina. Single quote or double quote, je use gare pani
huncha.
• Negative indexing le pachi bata count garcha. my_string[-1] le last character dincha.
Interview Notes:
• Immutable vaneko k ho? Example dinus.
• f-string (formatted string literals) sabse modern ra padhna sajilo tarika ho string formatting
ko lagi.
Control Flow
Program ko flow (bahab) lai control garne tools. K code chalaune, kati patak chalaune vanne kura
yesle decide garcha.
1. if, elif, else Statements
Yedi kunai condition True cha vane yo code chalaune, natra arko code chalaune. Yo decision making
ko lagi ho.
• if: Yedi yo condition True cha...
• elif: Mathi ko if False vaye, yedi yo condition True cha...
• else: Mathi ko kunai pani condition True vayena vane...
Logical Operators:
• and: Dubai condition True huna parcha.
• or: Kunai euta True vaye pugcha.
• not: True lai False ra False lai True banauncha.
Key Points/Tips:
• Indentation (space) dherai important cha. if block bhitra ko code ali agadi sarera (usually
4 spaces) lekhnu parcha.
• elif jati wota pani use garna milcha. else optional ho.
Common Mistakes:
• if age = 18: lekhnu. = assignment ko lagi ho. Comparison ko lagi == (barabar cha?) use
huncha.
Interview Notes:
• Conditional Expression (Ternary Operator): Ek line ma if-else lekhne tarika.
2. Loops (for and while)
Kunai code lai ** पटक-पटक (repeatedly) chalauna** loops ko prayog garincha.
• for loop: Kunai sequence (list, string, etc.) ko harek item ma ek-ek garera kaam garna. Kati
patak chalcha vanne thaha huda yo use huncha.
• while loop: Jaba samma condition True huncha, taba samma code repeat garne. Kati patak
chalcha vanne thaha nahuda yo use huncha.
Key Points/Tips:
• break: Loop lai bichmai rokna.
• continue: Current iteration skip garera arko iteration ma jana.
• Infinite loop: while loop ko condition sadhai True vayo vane loop kahile rokidaina. Yesbata
bachnu parcha.
Common Mistakes:
• while loop ma condition change garne variable lai update garna birsinu, jasle infinite loop
create garcha.
Interview Notes:
• "When would you use a for loop over a while loop?"
o Answer: "When I know the number of iterations in advance, like iterating over a
list, I use a for loop. When I need to loop until a certain condition is met, like
waiting for user input, I use a while loop."
3. match-case Statements
Yo Python 3.10 ma aako naya feature ho. Yo if-elif-else ko advanced version ho, especially dherai
options check garna parema. C/Java ko switch-case jastai ho
Key Points/Tips:
• _ (underscore) lai default case (jastai else) ko lagi use garincha.
• if-elif-else le garne sabai kaam yesle gardaina, tara specific value matching ko lagi dherai
clean dekhincha.
Interview Notes:
• Yo naya feature vako le, yesko barema thaha cha ki chaina vanera sodna sakcha. It shows
you are updated with the latest Python versions.
Membership Operators (in, not in)
Yo operator le kunai item, sequence (list, tuple, string) bhitra cha (in) ki chaina (not in) vanera
check garcha. Yesle True or False return garcha.
Interview Notes: Membership checking is much faster in sets and dictionary keys than in lists. List
ma check garda Python le suru dekhi ek-ek garera item khojcha (O(n)), tara set/dict ma direct check
huncha (O(1)).
🗃️ Data Structures
Multiple data items lai sangai, organized tarika le store garne containers.
1. Lists
List vaneko multiple items ko collection ho, jaslai euta variable ma rakhincha. Yo ordered (item ko
क्रम huncha) ra mutable (change garna milne) huncha.
Key Points/Tips:
• List lai square brackets [] le define garincha.
• List bhitra jun sukai data type (number, string, even arko list) rakhna milcha.
Common Mistakes:
• List copy garda new_list = old_list garnu. Yesle copy gardaina, eutai list lai duita naam
dincha. Euta ma change garda arko ma pani huncha. Sahi tarika: new_list = old_list.copy()
or new_list = old_list[:].
Interview Notes:
• List vs Tuple: List mutable (changeable) ho, tuple immutable (unchangeable) ho.
• List Comprehension: Ek line ma for loop lagayera list banaune choto tarika.
2D Collections (List of Lists)
2D collection vaneko list bhitra arko list ho. Yeslai matrix or grid jasto data store garna use
garincha, jastai tic-tac-toe board or spreadsheet data.
Key Points/Tips:
• Nested for loops are often used to iterate through 2D lists.
Tuples
Tuple pani list jastai ho, tara yo immutable huncha. Yesko matlab, ek choti banai sake pachi teslai
change garna mildaina (item thapna, hatauna, or badalna mildaina).
Key Points/Tips:
• Tuple lai parentheses () le define garincha.
• List vanda Tuple ali fast huncha.
• Jun data change garnu chaina, teslai tuple ma rakhda safe huncha. (e.g., coordinates, RGB
color codes).
Interview Notes:
• "Why use a tuple when you have lists?"
o Answer: "Tuples are used for data that should not be changed (immutability).
They are faster and use less memory than lists. They can also be used as keys in a
dictionary, while lists cannot."
3. Dictionaries
Dictionary le data lai key: value pair ma store garcha. Yo real-life dictionary jastai ho, jaha key
vaneko 'word' ra value vaneko tesko 'meaning' ho. Yo unordered (Python 3.7+ ma ordered) ra
mutable huncha.
Key Points/Tips:
• Dictionary lai curly braces {} le define garincha.
• Keys must be unique and immutable (string, number, or tuple). Values j pani huna sakcha.
Common Mistakes:
• Nabhako key access garna khojnu. student["address"] le error dincha. Safe tarika:
[Link]("address"), yesle None return garcha.
Interview Notes:
• Dictionaries are highly optimized for retrieving data. key use garera value khojna dherai
chito huncha, list ma jasto suru dekhi khojdai janu pardaina.
4. Sets
Set vaneko unique items ko collection ho. Yesma duplicate items hudainan ra yo unordered
huncha (item ko kunai specific क्रम hudaina).
Key Points/Tips:
• Set lai pani {} le define garincha, tara key:value pair hudaina.
• Khali set banauna s = {} nagarnu, yesle empty dictionary banaucha. Use s = set().
Interview Notes:
• "When would you use a set?"
o Answer: "When I need to store only unique elements and the order doesn't
matter. It's very efficient for checking if an element is present in the collection
(membership testing) and for mathematical set operations like union and
intersection."
🔧 Functions
Functions vaneko code ko ek reusable block ho. Eutai kaam dherai thau ma garnu parema, teslai
function bhitra lekhincha ra chahiyeko bela tyo function lai call garincha. Yesle code lai clean,
organized, ra D.R.Y. (Don't Repeat Yourself) banauncha.
1. Defining Functions
def keyword use garera function banaincha. Function le input (arguments) lina sakcha ra output
(return value) dina sakcha.
Key Points/Tips:
• Function ko naam meaningful hunu parcha (e.g., calculate_tax, get_user_info).
• return keyword le function bata value pathaucha. return pachi ko code chaldaina.
Common Mistakes:
• Function define matra garera call garna birsinu. Define gardai ma code chaldaina, call
garnu parcha.
• return garna parne thau ma print lekhnu. print le screen ma dekhaune kaam matra garcha,
value didaina.
Interview Notes:
• "What is the difference between a parameter and an argument?"
o Answer: Parameter vaneko function definition ma lekhine variable ho (e.g., name
in def greet(name)). Argument vaneko function call garda pass garine actual value
ho (e.g., "Ram" in greet("Ram")).
2. Default & Keyword Arguments
• Default Arguments: Function define garda parameter lai default value dine. Yedi user le
tyo argument pass garena vane, default value use huncha.
• Keyword Arguments: Function call garda parameter ko naam nai lekhna milcha. Yesle
argument ko order important hudaina.
Key Points/Tips:
• Default arguments wala parameters sadhai non-default parameters ko pachi aauna
parcha. def func(a, b=10) is correct, def func(a=10, b) is wrong.
Interview Notes:
• Keyword arguments le code ko readability badhaucha. Function call herera k value k ko
lagi ho vanera thaha huncha.
3. *args and **kwargs
Yo function le unlimited arguments lina sakne banaune special syntax ho.
• *args (Arguments): Function lai unlimited non-keyword arguments (as a tuple) pass garna
dincha.
• **kwargs (Keyword Arguments): Function lai unlimited keyword arguments (as a
dictionary) pass garna dincha
Key Points/Tips:
• Naam args ra kwargs nai huna parcha vanne chaina. Important kura * (asterisk) ra **
(double-asterisk) ho. Tara convention (chalan) yahi naam use garne cha.
Interview Notes:
• *args ra **kwargs le dherai flexible functions banauna madat garcha, jasto ki decorators
ra class initializers ma dherai use huncha.
4. Scope & if __name__ == "__main__"
• Scope: Variable kata-kata bata access garna milcha vanne rule ho. Local Scope (function
bhitra) ko variable bahira bata access garna mildaina. Global Scope (sabai vanda bahira)
ko variable sabai thau bata access garna milcha.
• if __name__ == "__main__": Yo block bhitra ko code taba matra chalcha jaba tyo file lai
direct run garincha. Yedi tyo file lai arko file ma import gariyo vane yo block chaldaina.
Fig: (--name--)
Interview Notes:
• if __name__ == "__main__" ko prayog script lai reusable module jastai banauna garincha.
Main execution logic yes bhitra rakhincha.
Object-Oriented Programming (OOP)
OOP vaneko programming garne ek style ho, jaha hami code lai objects ko aadhar ma structure
garchau. Real-world jastai (e.g., car, person, bank account).
1. Classes and Objects
• Class: Ek blueprint or template ho. Jastai, Car vanne class le car kasto huncha (properties:
color, brand) ra k garna sakcha (methods: start, stop) vanera define garcha.
• Object (Instance): Tyo blueprint bata baneko real item ho. Jastai, tesla_car vaneko Car
class ko ek object ho.
• __init__(): Yo ek special method (constructor) ho. Jaba object create huncha, yo aafai call
huncha. self le tyo particular object lai refer garcha.
Key Points/Tips:
• Class ko naam PascalCase ma lekhne chalan cha (e.g., MyClassName).
Interview Notes:
• "What is self?"
o Answer: self represents the instance (object) of the class. It is used to access the
variables and methods associated with that specific object.
Class Variables
Class variable vaneko tyo class ko sabai objects (instances) le share garne variable ho. Yo class
level ma define garincha, __init__ bhitra haina. Instance variable ([Link]) harek object ko
aafno huncha, tara class variable sabai ko lagi eutai huncha.
Interview Notes: "What is the difference between a class variable and an instance variable?" is a
very common OOP interview question.
Static & Class Methods
• Regular Method: Object (self) chahincha. (def my_method(self, ...)).
• @classmethod: Pura class (cls) chahincha, object chahidaina. Class variables ma kaam
garna dherai use huncha.
• @staticmethod: Na object (self) chahincha, na class (cls). Yo euta normal function jastai
ho tara class bhitra bascha.
Magic Methods (Dunder Methods)
Yo special methods haru ho jaslai double underscores (__) le suru ra end garincha (e.g., __init__,
__str__). Yeslai "Dunder" (Double Under) methods pani vanincha. Yesle Python ko built-in
operations (jastai +, len(), print()) lai hamro object ma kasari kaam garne vanera define garna
dincha.
@property Decorator
Yo decorator le euta method lai attribute (variable) jastai access garna dincha. Tapaile parenthesis
() bina nai method call garna saknuhuncha. Yeslai "getter" banauna dherai use garincha.
2. Inheritance
Inheritance vaneko parent class (base class) ko properties ra methods haru child class (derived
class) le paune process ho. Yesle code reusability badhaucha. "is-a" relationship (e.g., A Dog is a
type of Animal).
Key Points/Tips:
• super(): Child class bata parent class ko method lai call garna super() use huncha. Yo
__init__ ma dherai use huncha.
Interview Notes:
• Types of Inheritance: Single, Multiple, Multilevel, Hierarchical. Python supports all of
them, including Multiple Inheritance (euta child le dherai parent bata inherit garne).
3. Polymorphism & Duck Typing
• Polymorphism: "Many forms." Eutai naam ko method le alag-alag class ma alag-alag kaam
garne.
• Duck Typing: "If it walks like a duck and it quacks like a duck, then it must be a duck."
Python ma object ko type vanda tesko behavior (methods) important huncha. Kunai object
ma chahiyeko method cha vane, tyo use garna milcha, tesko class j sukai hos.
Yaha make_animal_speak function le speak() method vako jun pani object sanga kaam garcha. This
is also an example of Duck Typing.
Interview Notes:
• Polymorphism le code lai flexible ra generic banauna madat garcha. Tapaile if type(animal)
is Dog jasto check gari rakhnu pardaina.
Advanced Topics
Aba alikati advanced, tara dherai useful concepts haru herau.
1. Exception Handling (try...except)
Program chaldai garda auna sakne errors (exceptions) lai manage garne tarika ho. try block bhitra
error auna sakne code rakhincha. Yedi error aayo vane, program crash hunu ko satta except block
ko code chalcha.
Key Points/Tips:
• finally block optional ho. File close garne, database connection band garne jasto cleanup
code yaha rakhincha.
Interview Notes:
• "Why is exception handling important?"
o Answer: It prevents the program from crashing due to unexpected errors. It allows
us to handle errors gracefully and provide meaningful feedback to the user.
2. File I/O (Reading & Writing Files)
Python use garera file (e.g., .txt) ma data lekhna (write) ra padhna (read) milcha. with open(...)
syntax use garnu best practice ho, kinaki yesle file lai aafai close garcha.
Interview Notes:
• Difference between modes: 'r' (read), 'w' (write, overwrites), 'a' (append, last ma thapcha),
'r+' (read and write).
• Why is with open(...) preferred? It ensures the file is properly closed even if an error occurs
inside the block.
3. Dates & Times (datetime module)
Date ra time sanga kaam garna Python ko built-in datetime module dherai powerful cha.
Interview Notes:
• strftime (string from time) is for formatting a datetime object into a string.
• strptime (string parse time) is for parsing a string into a datetime object.
4. API Requests
API (Application Programming Interface) vaneko dui wota software le ek-apas ma kura garne tarika
ho. Web API use garera hami internet bata data (e.g., weather, news, stock prices) tanna sakchau.
Yesko lagi requests library dherai popular cha.
Concept (No code run needed):
1. Install library: pip install requests
2. Find API URL (Endpoint): Jastai, [Link]
3. Make a Request: [Link](url) le tyo URL bata data magcha.
4. Get Response: Server le data (usually JSON format ma) pathaucha.
5. Process Data: Tyo JSON data lai dictionary jastai use garera chahiyeko information nikalne.
Interview Notes:
• Common HTTP methods: GET (data lina), POST (data pathauna/create garna), PUT (update
garna), DELETE (delete garna).
• Common status codes: 200 (OK), 404 (Not Found), 500 (Server Error), 403 (Forbidden).
Multithreading
Multithreading vaneko euta program bhitra dherai kaam haru ekai choti jasto gari chalaune
(concurrently) process ho. Euta main program (process) bhitra dherai "threads of execution"
hunchan. Yo I/O-bound tasks (jastai file download garne, API call garne) ko lagi dherai useful
huncha, jaha program data kurnu parcha.
Concept (No code run needed):
1. Import threading module: import threading
2. Define a function: Yo function tyo thread le garne kaam ho.
3. Create a Thread object: thread = [Link](target=my_function)
4. Start the Thread: [Link]() le tyo function lai naya thread ma chalauna suru garcha.
Main program aghi badhirahancha.
5. Wait for thread to finish (optional): [Link]() le main program lai tyo thread ko kaam
nasakkesamma kurnu vancha.