BCA / B.Tech 9 min read

Basic Operations in Hindi

Basic Operations in python in Hindi | पाइथन में बेसिक ऑपरेशन हिंदी में : 


  • Python प्रोग्रामिंग लैंग्वेज़ में विभिन्न data structures के साथ कई प्रकार के basic operations किए जाते हैं जैसे कि अपडेट करना (Updating), इनsertion (Insertion), डिलीशन (Deletion) और सेलेक्शन (Selection)। ये operations किसी भी data structure (जैसे list, tuple, dictionary, set आदि) के महत्वपूर्ण हिस्से होते हैं। 
  • Python में basic operations जैसे कि अपडेट करना, इनsertion, डिलीशन, और सेलेक्शन किसी भी data structure को efficiently manage करने के लिए बहुत महत्वपूर्ण होते हैं।
  •  इन operations का उपयोग list, dictionary, set और tuple जैसी data structures के साथ किया जा सकता है। यह operations data को manage और modify करने में सुविधा प्रदान करते हैं और प्रोग्राम को अधिक dynamic बनाते हैं।
  • इस उत्तर में, हम इन operations पर गहराई से चर्चा करेंगे, विशेषकर Python lists के संदर्भ में, लेकिन अन्य data structures पर भी लागू हो सकते हैं।

1. अपडेट करना (Updating) :

Python में किसी existing data को बदलने की प्रक्रिया को updating कहा जाता है। जब हम किसी list या dictionary जैसी data structure में कोई value बदलते हैं, तो इसे updating कहा जाता है।

Syntax (List के लिए):


list[index] = new_value

उदाहरण:

my_list = [10, 20, 30, 40]
my_list[1] = 25  # Index 1 की value बदल कर 25 कर दी गई
print(my_list)  # Output: [10, 25, 30, 40]

Dictionary में Updating:

my_dict = {'name': 'Ravi', 'age': 25}
my_dict['age'] = 26  # 'age' की value 26 कर दी गई
print(my_dict)  # Output: {'name': 'Ravi', 'age': 26}

Conclusion:

  • Updating किसी data structure में एक existing element को नई value से replace करने की प्रक्रिया है।
  • Updating ऑपरेशन सरल और efficient है, और यह केवल कुछ समय में किया जा सकता है।

2. इनsertion (Insertion):

Python में Insertion का अर्थ है data structure में किसी नए element को जोड़ना। यह operation lists, dictionaries, और sets जैसी data structures में बहुत आम है। Python में Insertion अलग-अलग तरीकों से किया जा सकता है, जैसे कि list के अंत में या किसी specific position पर।

List में Insertion:

  • append() Method: List के अंत में नया element जोड़ने के लिए।
  • insert() Method: List में किसी specific index पर element जोड़ने के लिए।

Syntax (List के लिए):

  • list.append(element)  # List के अंत में जोड़ता है
  • list.insert(index, element)  # Specified index पर जोड़ता है

उदाहरण :

my_list = [1, 2, 3]
my_list.append(4)  # List के अंत में 4 जोड़ता है
print(my_list)  # Output: [1, 2, 3, 4]

my_list.insert(1, 10)  # Index 1 पर 10 जोड़ता है
print(my_list)  # Output: [1, 10, 2, 3, 4]
Dictionary में Insertion:


my_dict = {'name': 'Ravi'}
my_dict['age'] = 25  # 'age' key जोड़ता है
print(my_dict)  # Output: {'name': 'Ravi', 'age': 25}

Conclusion:

  • Insertion operation lists में नए elements को add करने के लिए इस्तेमाल किया जाता है।
  • यह data structure को dynamically modify करने में मदद करता है।

3. डिलीशन (Deletion):

Python में Deletion का मतलब किसी element को data structure से remove करना होता है। आप specific index, value, या पूरे data structure को delete कर सकते हैं। List, dictionary, 
और set जैसी data structures में Deletion के कई तरीके होते हैं।

List में Deletion:

  • remove() Method: Specific value को remove करता है।
  • pop() Method: Specific index या last element को remove करता है।
  • del Keyword: किसी specific index पर element या पूरी list को delete करता है।

Syntax (List के लिए):

  • list.remove(value)  # Specific value को remove करता है
  • list.pop(index)  # Specified index से element remove करता है, default last element
  • del list[index]  # Specified index का element delete करता है

उदाहरण :

my_list = [1, 2, 3, 4, 5]
my_list.remove(3)  # 3 को remove करता है
print(my_list)  # Output: [1, 2, 4, 5]

my_list.pop(1)  # Index 1 का element (2) remove करता है
print(my_list)  # Output: [1, 4, 5]

del my_list[0]  # Index 0 का element (1) remove करता है
print(my_list)  # Output: [4, 5]

Dictionary में Deletion:

my_dict = {'name': 'Ravi', 'age': 25}
del my_dict['age']  # 'age' key को remove करता है
print(my_dict)  # Output: {'name': 'Ravi'}


Conclusion :

  • Deletion operation lists और dictionaries में elements को remove करने के लिए होता है।
  • यह memory को efficiently manage करने में मदद करता है और unwanted data को हटाने की सुविधा देता है।

4. सेलेक्शन (Selection):

Python में Selection का मतलब है किसी specific element या group of elements को select करना। Selection operation list slicing और indexing के द्वारा किया जाता है। Slicing और indexing Python में powerful tools हैं जिनका उपयोग हम list, tuple और strings में आसानी से कर सकते हैं।

List में Selection:

  • Indexing: किसी specific element को select करने के लिए।
  • Slicing: एक range में elements को select करने के लिए।

Syntax (List के लिए):

  • list[index]  # Specified index से element select करता है
  • list[start:end]  # start से end-1 तक elements को select करता है

उदाहरण:

my_list = [10, 20, 30, 40, 50]

# Indexing
print(my_list[2])  # Output: 30

# Slicing
print(my_list[1:4])  # Output: [20, 30, 40]

Conclusion:

  • Selection operation list या अन्य data structures से specific elements को select करने के लिए किया जाता है।
  • यह प्रोग्राम में flexibility और efficiency बढ़ाने में मदद करता है।