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