Posted By Naveen Singh on 25 Apr 2023
python-programPython में array एक non primitive data type होता है, जो की एक समय पर एक से ज्यादा elements को store करता है। Array एक तरह के special variables होते है, जिसका प्रयोग हम एक से
ज्यादा elements को store करने के लिए करते हैं। जैसे आपके पास किसी items की list है (list of fruits ), fruits को हम single variable में store करे तो वे कुछ इस प्रकार से दिखेंगे।
Example-:
fruit 1= "apple"
fruit 2= "mango"
fruit 3= "banana"
इस प्रकार से हम array को create कर सकते है, और इस तरह से आप कई सारी values को single variable में store करवा सकते है।
Python में हम array elements को उसके index number के through access कर सकते है।
Example-:
fruit = ["apple","mango","banana"]
a = fruit[1]
print(a)
Output-:
mango
इसी तरह से आप array elements को modify भी कर सकते है।
Example-:
fruit = ["apple","mango","banana"]
fruit[1] = "gràpes"
print(fruit)
Output-:
["apple","grapes","banana"]
Python में array की length check करने के लिए हम len() function का प्रयोग करते है। जिसका through हम array की length पता कर सकते है। Array में len() function array की length
को return करता है।
Example-:
fruit = ["apple","mango","banana"]
a = len(fruit)
print(a)
Output-:
3
Python में array elements को हम for loop की सहायता से access कर सकते हैं।
Example-:
fruit = ["apple","mango","banana"]
for i in fruit:
print(i)
Output-:
apple
mango
banana
Python में हम append() function की सहायता से array elements को add कर सकते है। append() function elements को array के last में add करता है।
Example-:
fruit = ["apple","mango","banana"]
fruit.append("orange")
print(fruit)
Output-:
["apple","grapes","banana",”orange”]
ऊपर दिए गए example में orange element को add किया है।
pop() function की सहायता से हम array में से elements को remove कर सकते है। pop() function elements को उसकी specified position से remove कर देता है।
Example-:
fruit = ["apple","mango","banana"]
fruit.pop(0)
Output-:
["grapes","banana"]
Array में हम elements को remove() function की सहायता से भी remove कर सकते हैं, जो कि element को उसके specified name से remove करता है मतलब की हमे remove() function में
element के name को pass करना पड़ता है।
Example-:
fruit = ["apple","mango","banana"]
fruit.remove(“apple”)
print(fruit)
Output-:
["grapes","banana"]
I Hope आपको array क्या होता है? array python में कैसे work करता है, और array के functions के बारे में आपको जानकारी मिली होगी। यदि कोई doubt है तो comment section में comment कीजिए।