python python tutorial in hindi python data type python variable python operators conditional statements in python python tuple

Python List

Table of Contents All Chapters 1. Python List 2. Nested List 3. Range List 4. List Indexing 5. list Methods   Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String Python List Hamburger Toggle Menu Table of Contents 1. Python List 2. Nested List 3. Range List 4. List Indexing 5. list Methods Python List in Hindi What is Python List in hindi Python List in hindi : python में list बनाने के लिए हम square bracket का use करते हैं, और उनके अंदर values को comma से  separate करके Store करते हैं. जैसा की example में दिया गया है 🐍 lists.py Copy to clipboard 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 number_list = [5, 48, 9, 789, 0, 45] string_list = ["mango", "banana", "apple"] mixed_list = ["apple", 56, True, 2.8] empty_list = [] print(number_list) print(string_list) print(mixed_list) print(empty_list) # output: # [5, 48, 9, 789, 0, 45] # ['mango', 'banana', 'apple'] # ['apple', 56, True, 2.8] # [] What is Nested List in python in hindi अगर हम list केअंदर list बनाते हैं तो इसे nested list कहा जाएगा. for Example 🐍 nested list.py Copy to clipboard 1 2 3 4 nested_list = [[5,8],[4,1],[2,8]] print(nested_list) # Output: # [[5,8],[4,1],[2,8]] what is range list in python in hindi python मे range() एक method होता है, जिसके help से हम python List को create कर सकते है। जो list range() method के help से create किया जाता है उन्हे range list कहा जाता है। 🐍 range list.py Copy to clipboard 1 2 3 4 num = list(range(1, 10)) print(num) # Output: # [1, 2, 3, 4, 5, 6, 7, 8, 9] what is list comprehension in python in hindi pythhon मे list comprehension एक तरीका है list create करने का  🐍 create a list.py Copy to clipboard 1 2 3 4 comprehension_list = [a**2 for a in range(1, 6)] print(comprehension_list) # Output: # [1, 4, 9, 16, 25] what is list indexing in python in hindi or how to access list items अगर हम python list मे से किसी particular item को access करना चाहते है तो indexing का use करते है। indexing positive और negative दोनों तरीके से की जा सकती है। positive indexing मे list के first item को access करने के लिए “0” का use करते है और negative indexing मे list के last item को access करने के लिए “-1” का use  करते है। 🐍 list indexing.py Copy to clipboard 1 2 3 4 5 6 my_list = ["banana", "grapes", "apple"] print(my_list[0]) print(my_list[-1]) # Output: # banana # apple how to change list items in python in hindi python मे हम list के items को direct assignment के through change कर सकते है। list के जिस भी item को change करना उसे indexing के through select किया जाता है।  🐍 adding item.py Copy to clipboard 1 2 3 4 5 my_list = ["banana", "grapes", "apple"] my_list[1] = "orange" print(my_list) # Output: # ['banana', 'orange', 'apple'] how to iterate list items in python in hindi python मे हम list के items को for loop के through iterate कर सकते है।  🐍 iterate items.py Copy to clipboard 1 2 3 4 5 my_list = ["banana", "grapes", "apple"] for i in my_list: print(my_list) # Output: # ['banana', 'grapes', 'apple'] how to add lists in python in hindi python मे हम “+” operator का use करके lists को आसानी से add  कर सकते है। 🐍 adding lists.py Copy to clipboard 1 2 3 4 5 list1 = ["banana", "grapes", "apple"] list2 = [1, 2, 3] print(list1 + list2) # Output: # ['banana', 'grapes', 'apple', 1, 2, 3] List Methods in Hindi python मे list के लिए कई सारे build-in methods होते है. Syntex: method को किसी भी variable के साथ use करने के लिए dot ( . ) का use करते है। Example: append() : इस method का use करके हम string के सभी lower case letters को upper case मे कर सकते है।  🐍 append.py Copy to clipboard 1 2 3 4 5 list1 = ["banana", "grapes", "apple"] list1.append("orange") print(list1) # Output: # ['banana', 'grapes', 'apple', 'orange'] यहाँ कुछ list के methods दिए गए है जिन्हे आप इसी तरह से list के साथ use करके इनके result को देख सकते है। append(): नए element को list के end मे add करता है।  insert(): नए element को specified index पर insert करता है। remove(): किसी Specified value को list मे से remove करता है। pop(): किसी Specified index परर element को remove करता है। index(): किसी Specified value का first occurrence का index return करता है।  count(): किस Specified value का occurrences count करता है। sort(): List के elements को sort करता है। reverse(): List के elements को reverse करता है। 🐍 list methods.py Copy to clipboard 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 # Ek empty list banate hain my_list = [] # 1. append() – End me elements add karte hain my_list.append(10) my_list.append(20) my_list.append(30) print("After append:", my_list) # [10, 20, 30] # 2. insert() – Specific index par element insert karte hain my_list.insert(1, 15) # Index 1 par 15 insert hoga print("After insert:", my_list) # [10, 15, 20, 30] # 3. remove() – Specific value ko remove karte hain my_list.remove(20) print("After remove:", my_list) # [10, 15, 30] # 4. pop() – Specific index se element remove aur return karte hain removed_element = my_list.pop(1) # Index 1 ka element hataenge print("Popped element:", removed_element) # 15 print("After pop:", my_list) # [10, 30] # 5. index() – Kisi value ka first index find karte hain index_of_30 = my_list.index(30) print("Index of 30:", index_of_30) # 1 # 6. count() – Kisi value ka count nikalte hain count_of_10 = my_list.count(10) print("Count of 10:", count_of_10) # 1 # 7. sort() – List ko

python python tutorial in hindi python data type python variable python operators conditional statements in python python tuple

Python String

Table of Contents All Chapters 1. Python String 2. String Indexing 3. String Slicing 4. String Concatenation 5. String Formatting 6. String Methods   Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String Python List Hamburger Toggle Menu Table of Contents 1. Python String 2. String Indexing 3. String Slicing 4. String Concatenation 5. String Formatting 6. String Methods Python String What is Python String in Hindi Python String : Single and double quote के अंदर हम कुछ लिखते हैं तो यह string कहलाता है. Triple quote के अंदर हम कुछ लिखते हैं तो भी यह string कहलाता है इसका use हम multi line string के लिए करते हैं. 🐍 string.py Copy to clipboard 1 2 3 4 print("this is single line string") print("""this is multi-line string""") String Indexing in Hindi अगर हम string में से किसी specific data को print करना चाहते हैं तो indexing का use करते हैं.  python string में characters का indexing 0 से start होता है, और negative indexing end से start होता है  -1 last character को represent करता है. 🐍 string indexing.py Copy to clipboard 1 2 3 4 5 6 text = "hello, world!" print(text[0]) print(text[-1]) #output # h # ! String Slicing in Hindi slicing का use string के Sab string पाने के लिए होता है, start: Ye wo index hai jahan se slicing start hoti hai. stop: Ye wo index hai jahan tak slicing hoti hai. step: Ye optional parameter hai jo batata hai ki kitne steps ka difference rakhna hai. Agar aap start, stop, ya step ko nahi dete, to default values use hoti hain: Default value for start is 0. Default value for stop is length of the string. Default value for step is 1 🐍 string slicing.py Copy to clipboard 1 2 3 4 5 6 7 8 9 10 11 12 text = "hello, world!" print(text[0:5]) print(text[7:]) print(text[:5]) print(text[-6:-1]) print(text[0:5:2]) #output # hello # world! # hello # world # hlo String Concatenation in Hindi string concatenation का मतलब होता है एक या एक से अधिक strings को add करके single string मे convert करना।  string को concatenate करने के लिए + operator या join methode का use किया जाता है। 🐍 string concatenation.py Copy to clipboard 1 2 3 4 5 6 7 8 9 10 11 12 13 a = "python" b = "programing" c = "hub" # using + operator print(a +" "+ b +" "+ c) # using join methode print(" ".join([a,b,c])) # output # python programing hub # python programing hub NOTE: string concatenation मे हमने double quote ( ” ” ) का use इसलिए किया है ताकि हम strings के बीच मे space दे सके अगर double quote नहीं लगाएंगे तो सारे strings एक मे mix होकर single word बन जाएंगे।  अगर आप double quote के अंदर कुछ लिखेंगे तो वो भी string मे join हो जाएगा। String Formatting in Hindi अगर हम चाहते है कि string मे variables या expressions के value को direct insert कर सके तो हमे string formatting का उसे करना होगा। python मे string formatting बनाने के लिए % operator, str.format() method और f-strings का use करते है।  % Operator 🐍 formatting 1.py Copy to clipboard 1 2 3 name = "Lisa" age = 25 print("Hello my name is %s and I am %d year old." %(name, age)) str.format Method 🐍 formatting 2.py Copy to clipboard 1 2 3 4 5 name = "Lisa" age = 25 print("My name is {} and I am {} years old.".format(name, age)) # Output: My name is Lisa and I am 25 years old. f-strings 🐍 formatting 3.py Copy to clipboard 1 2 3 4 5 6 7 8 9 name = "Lisa" age = 25 print(f"My name is {name} and I am {age} years old.") # Output: My name is Charlie and I am 35 years old. # Aap expressions bhi use kar sakte hain print(f"Next year, I will be {age + 1} years old.") # Output: Next year, I will be 26 years old. String Methods in Hindi python मे string के लिए कई सारे build-in methods होते है जिन्हे use करने पर string अलग अलग तरीके से perform करता है। Syntex: method को किसी भी variable के साथ use करने के लिए dot ( . ) का use करते है। Example: str.upper() : इस method का use करके हम string के सभी lower case letters को upper case मे कर सकते है।  🐍 string method.py Copy to clipboard 1 2 3 4 5 text = "hello" result = text.upper() print(result) # Output: HELLO यहाँ कुछ methods दिए गए है जिन्हे आप इसी तरह से string के साथ use करके इनके result को देख सकते है। आपको str के जागह अपने string या string variable को use करना है। Method Description str.upper() String ko uppercase me convert karta hai str.lower() String ko lowercase me convert karta hai str.capitalize() Pehla letter uppercase karta hai, baaki lowercase str.title() Har word ka pehla letter uppercase karta hai str.strip() Start aur end ke whitespace (ya characters) remove karta hai str.lstrip() Left se whitespace (ya characters) hatata hai str.rstrip() Right se whitespace (ya characters) hatata hai str.replace(old, new) String me kisi substring ko replace karta hai str.split(separator) String ko list me todta hai str.join(iterable) List (ya iterable) ko string me jodta hai str.find(sub) Substring ka index return karta hai (nahi mila to -1) str.index(sub) Substring ka index deta hai (error deta hai agar na mile) str.count(sub) Substring kitni baar aaya hai, wo count karta hai str.startswith(prefix) Check karta hai ki string kisi prefix se start ho rahi hai ya nahi str.endswith(suffix) Check karta hai ki string kisi suffix se end ho rahi hai ya nahi str.isalpha() Check karta hai ki sab characters alphabets hain ya nahi str.isdigit() Check karta hai ki sab characters digits hain ya nahi str.isalnum() Alphabets + Digits hain to True return karta hai str.isspace() Agar string me sirf whitespace ho to True str.islower() Check karta hai

python python tutorial in hindi python data type python variable python operators conditional statements in python python tuple

Python Loops

Table of Contents All Chapters 1. Python Loops 2. While Loop      2.1. Nested While Loop 3. For Loop      3.1. Range Function      3.2. Nested For Loop 4. Bresk Statement 5. Continue statement   Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String Python List Hamburger Toggle Menu Table of Contents 1. Python Loops 2. While Loop      2.1. Nested While Loop 3. For Loop      3.1. Range Function      3.2. Nested For Loop 4. Bresk Statement 5. Continue statement Loops in Python in hindi What is Loops in Python in hindi python मे अगर हमे किसी block of code को बार बार चलाना होता है तो हम loops का use करते है। python मे 2 types के loop होते है- 1. For Loop  2. While Loop  What is While Loop in Hindi Python में जब हमें किसी block को Repeatedly execute करना होता है तो हम while loop का use करते हैं  while loop एक control flow statement है यह किसी block को तब तक execute करता है जब तक condition true होती है How While Loop Work while loop start होने से पहले Condition को Check करता है अगर Condition true होती है तो loop के अंदर का Code execute होता है एक बार execution होने के बाद block के अंदर condition update होता है और Condition true होता है तो code का execution फिर से होता है और यह प्रक्रिया तब तक चलता रहता है जब तक Condition False ना हो जाए. इसलिए हमें Condition को सावधानीपूर्वक देना होता है वरना loop infinite हो जाएगा और code का Execution कभी रुकेगा ही नहीं example से समझते हैं 🐍 while.py Copy to clipboard 1 2 3 4 num = 1 # Initialization while num <= 5: # Condition print(num) num += 1 # Increment Nested While Loop जब हम while loop के अंदर while loop को used करते हैं तो इसे nested while loop बोला जाता है चलिए इस एक example के through समझते हैं 🐍 nested while.py Copy to clipboard 1 2 3 4 5 6 7 8 i = 1 while i <= 3: # Outer loop (Rows) j = 1 while j <= 3: # Inner loop (Columns) print("*", end=" ") # Print star in the same row j += 1 print() # Move to the next line i += 1 What is For Loop in Hindi for loop एक control flow statement है इसका use हम generally sequence (जैसे –  list, set, string, etc.) के Elements पर perform करने के लिए करते हैंFor loop elements को sequence से एक-एक करके retrieve करता है  Example के through समझते हैं 🐍 for.py Copy to clipboard 1 2 3 4 fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) What is Range Function in Hindi range एक function है जिसका  use numeric sequence generate करने के लिए होता है यह function एक  sequence के number को  return करता है जो का  look में  I treat किया जा सकता है How Range Function Work  Start : यह Range की  starting value होती है जो  by default 0 होता है मतलब अगर हमने range में  starting value नहीं दिया है तो  for loop by default इस  value को 0 मानेगा but अगर हमने कोई value दिया है तो और loop वहीं से शुरू होगा  Stop : यह ending value होती है हम range में stop की value जितनी रखेंगे और look उतना बार code को Execute करेगा  Step :  यह increment value होती है जो red fault 1 रहता है मतलब हम range में increment value ना देतो इसका By default 1 एक माना जाएगा मतलबHot का  execution एक-एक  step में करेगा  example के through समझते हैं 🐍 range.py Copy to clipboard 1 2 for num in range(1, 10, 2): # Step = 2 print(num) Nested For Loop अगर हम For loop के अंदर भी for loop का use करते हैं तो इसे nested for loop बोला जाता है Example से समझते हैं 🐍 nested for.py Copy to clipboard 1 2 3 4 for i in range(3): # Outer loop (rows) for j in range(3): # Inner loop (columns) print("*", end=" ") # Print in same line print() # Move to next line What is Break Statement in Hindi अगर हमें Loop को Permanently terminate करना होता है तो हम Break का use करते हैं, लिए break को अच्छे से समझने के लिए एक example देखते हैं 🐍 break.py Copy to clipboard 1 2 3 4 for num in range(1, 6): if num == 3: break # Stops when num = 3 print(num) What is Continue Statement in Hindi अगर हम loop में current Iteration को  skip करके next iteration पर jump करना चाहते हैं तो continue statement का use करते हैं  example के  through अच्छे से समझते हैं 🐍 continue.py Copy to clipboard 1 2 3 4 for num in range(1, 6): if num == 3: continue # Skips 3 print(num) उम्मीद करते है कि आपको loops in python अच्छे समझ मे आ गया होगा । अपने learning को continue रखने के लिए next button पर click करे, Previous Next Add a comment… Cancel Reply Logged in as Python Programming Hub. Edit your profile. Log out? Required fields are marked * Message*

Scroll to Top