Seedha content par jao
🤖 Python Hindi Bot
Namaste! Main Python Hindi Bot hoon 🐍
Python ya AI se related kuch bhi type karke pucho, ya neeche se quick sawaal chuno.
WhatsApp

Stay Connected with PythonHindii

Join our WhatsApp Community to get the latest Python tutorials, coding tips, interview questions, project updates, and learning resources directly on your phone.

Join WhatsApp Community
⇧
Python Hindi Logo
Python in Hindi | Programming Education

Python Array क्या है? | Complete Guide for Beginners

Python Arrays in Hindi - Complete Guide for Beginners

Python Array

Python में हमने List के बारे में पढ़ा, जिसमें अलग-अलग data types की values एक साथ रखी जा सकती हैं। लेकिन Python में एक और data structure है — Array — जो List जैसा ही दिखता है, मगर इसमें सिर्फ एक ही data type की values रखी जा सकती हैं।

अगर आपने अभी Python Lists Complete Guide in Hindi नहीं पढ़ा है, तो पहले वो article पढ़ना बहुत उपयोगी रहेगा, क्योंकि इस article में हम Array और List का लगातार comparison करेंगे। Examples खुद run करने के लिए हमारा Online Python Editor & Compiler use कर सकते हैं।

🎥 Video में पूरा Topic समझें

Python Array क्या है?

Array एक ऐसा data structure है जिसमें एक जैसी data type की कई values एक क्रम (order) में रखी जाती हैं।

सरल भाषा में — Array एक ऐसी List है जिसमें सिर्फ एक ही तरह का data रखा जा सकता है।
Example
from array import array numbers = array('i', [10, 20, 30, 40]) print(numbers)

Output:

array('i', [10, 20, 30, 40])
Try it Yourself »

Python में array module

List, Tuple, Set और Dictionary की तरह Array Python का built-in data type नहीं है — इसे इस्तेमाल करने के लिए Python के array module की जरूरत पड़ती है।

Note: अगर सिर्फ array लिखकर इस्तेमाल करने की कोशिश करेंगे बिना import किए, तो Python NameError देगा।

from array import array

Array इस्तेमाल करने से पहले उसे array module से import करना जरूरी है।

Syntax
from array import array

यह line बताती है — array नाम के module से array नाम का function ले आओ, जिससे नया array बनाया जा सके।

Array Create करना

Syntax
array_name = array(typecode, [value1, value2, value3])
Example
from array import array marks = array('i', [85, 90, 78, 92]) print(marks)

Output:

array('i', [85, 90, 78, 92])
Try it Yourself »

Type Code क्या है?

Type Code एक छोटा सा character होता है जो बताता है कि Array में किस तरह का data रखा जाएगा — जैसे integer, float, आदि।

Type CodeData Type
'i'Integer (Signed)
'f'Float
'd'Double (बड़े decimal numbers)
'u'Unicode Character
Example — Float Array
from array import array prices = array('f', [99.5, 149.0, 249.99]) print(prices)

Output:

array('f', [99.5, 149.0, 249.99])
Try it Yourself »

Same Type के Elements

Array की सबसे बड़ी पहचान यही है कि उसमें सिर्फ एक जैसी data type की values होनी चाहिए — अलग-अलग types मिलाने पर Python error देता है।

Example — यह error देगा
from array import array mixed = array('i', [10, "twenty", 30]) # TypeError

Output:

TypeError: an integer is required

चूंकि Type Code 'i' दिया गया था (integer), इसलिए इसमें string value देने पर error आया।

Array Indexing

Array में भी List की तरह हर element की एक position (index) होती है।

marks = [85, 90, 78, 92] Index → 0 1 2 3

Positive और Negative Indexing

Example — Positive Indexing
from array import array marks = array('i', [85, 90, 78, 92]) print(marks[0]) print(marks[2])

Output:

85 78
Try it Yourself »
Example — Negative Indexing
from array import array marks = array('i', [85, 90, 78, 92]) print(marks[-1]) print(marks[-2])

Output:

92 78

Negative indexing में counting आखिर से होती है — last element का index -1 होता है।

Try it Yourself »

Array Value Update करना

Example
from array import array marks = array('i', [85, 90, 78, 92]) marks[1] = 95 print(marks)

Output:

array('i', [85, 95, 78, 92])
Try it Yourself »

append()

append() से Array के आखिर में एक नया element जोड़ा जाता है — बस ध्यान रहे कि वह value उसी data type की हो जो Array के Type Code से match करे।

Example
from array import array marks = array('i', [85, 90, 78]) marks.append(100) print(marks)

Output:

array('i', [85, 90, 78, 100])
Try it Yourself »

insert()

insert() से किसी specific position पर element जोड़ा जा सकता है।

Example
from array import array marks = array('i', [85, 90, 78]) marks.insert(1, 99) print(marks)

Output:

array('i', [85, 99, 90, 78])
Try it Yourself »

remove()

remove() से किसी दी गई value को Array से हटाया जाता है।

Example
from array import array marks = array('i', [85, 90, 78]) marks.remove(90) print(marks)

Output:

array('i', [85, 78])
Try it Yourself »

pop()

pop() से Array में से element हटाया जाता है — index न दिया जाए तो यह आखिरी element हटाता है, और हटाई गई value भी return करता है।

Example
from array import array marks = array('i', [85, 90, 78]) removed = marks.pop() print(marks) print("Removed:", removed)

Output:

array('i', [85, 90]) Removed: 78
Try it Yourself »
Methodकाम
append(value)आखिर में element जोड़ता है
insert(index, value)दी गई position पर element जोड़ता है
remove(value)दी गई value को हटाता है
pop(index)Element हटाकर उसकी value return करता है

len()

Example
from array import array marks = array('i', [85, 90, 78, 92]) print(len(marks))

Output:

4
Try it Yourself »

in Operator

Example
from array import array marks = array('i', [85, 90, 78, 92]) print(90 in marks) print(50 in marks)

Output:

True False
Try it Yourself »

Practical Marks Example

Example
from array import array marks = array('i', [85, 90, 78, 92]) # नया mark जोड़ना marks.append(88) # बीच में एक mark जोड़ना marks.insert(2, 95) # कोई mark हटाना marks.remove(78) print("Final Marks:", marks) print("Total Subjects:", len(marks)) print("Is 90 present:", 90 in marks)

Output:

Final Marks: array('i', [85, 90, 95, 92, 88]) Total Subjects: 5 Is 90 present: True

यहाँ append(), insert(), remove(), len() और in — सारे एक साथ इस्तेमाल किए गए हैं।

Try it Yourself »

Python List और Array का Basic Difference

FeatureListArray
Built-in?हाँ, कुछ import की जरूरत नहींनहीं, array module चाहिए
Data TypesMixed data types allowedसिर्फ एक जैसी data type
Memoryज्यादा memory लेती हैकम memory लेता है (same type होने से)
Use CaseGeneral-purpose data रखने के लिएबड़ी मात्रा में एक जैसी numeric values के लिए

Common Beginner Mistakes

❌ बिना import किए Array इस्तेमाल करना
numbers = array('i', [1, 2, 3]) # NameError
✅ सही तरीका
from array import array numbers = array('i', [1, 2, 3])
❌ अलग-अलग Data Types मिलाना
mixed = array('i', [1, "two", 3]) # TypeError
✅ सही तरीका — सिर्फ एक ही type रखें
numbers = array('i', [1, 2, 3])
❌ Type Code भूल जाना
numbers = array([1, 2, 3]) # TypeError: missing typecode
✅ सही तरीका
numbers = array('i', [1, 2, 3])
❌ Array और List को Confuse करना

List में कोई भी mixed data types रखे जा सकते हैं, लेकिन Array में हमेशा एक जैसी data type की values ही रखनी होती हैं — यह भूलने से TypeError आता है।

Exercise ?

Python में Array इस्तेमाल करने के लिए किस module से import करना जरूरी है?

list module
array module
collections module

Coding Challenge और Final Revision

अब खुद अपने Online Python Editor में इन challenges को solve कीजिए:

  1. Integer type code 'i' के साथ अपने 5 favorite numbers की एक array बनाइए।
  2. उस array में append() से एक नया number जोड़िए।
  3. insert() से किसी position पर एक number जोड़िए।
  4. remove() से कोई एक number हटाइए।
  5. Positive और negative indexing से पहला और आखिरी element print कीजिए।
  6. len() और in का इस्तेमाल करके array की length और किसी number की मौजूदगी check कीजिए।

Quick Revision

ConceptSyntax / Example
Importfrom array import array
Array बनानाarray('i', [1, 2, 3])
Type Code'i' Integer, 'f' Float, 'd' Double
Positive Indexingarr[0] → पहला element
Negative Indexingarr[-1] → आखिरी element
append() / insert() / remove() / pop()List जैसे ही काम करते हैं
len() / inLength और membership check

FAQ

Python में Array क्या है?

Array Python का एक data structure है जिसमें सिर्फ एक जैसी data type की values को एक क्रम में रखा जाता है, और इसे इस्तेमाल करने के लिए array module import करना पड़ता है।

Array और List में मुख्य फर्क क्या है?

List में अलग-अलग data types की values एक साथ रखी जा सकती हैं और यह built-in है, जबकि Array में सिर्फ एक जैसी data type की values रखी जा सकती हैं और इसके लिए module import करना पड़ता है।

Type Code क्या होता है?

Type Code एक character है जो बताता है कि Array में किस data type की values रखी जाएंगी — जैसे 'i' integer के लिए और 'f' float के लिए।

क्या Array में अलग-अलग data types रख सकते हैं?

नहीं। Array में सिर्फ एक जैसी data type की values रखी जा सकती हैं — अलग type की value डालने पर Python TypeError देता है।

Array कब इस्तेमाल करना चाहिए?

जब बड़ी मात्रा में एक जैसी (सिर्फ numeric) values रखनी हों और memory efficiency जरूरी हो, तब List की जगह Array इस्तेमाल करना बेहतर होता है।

Summary

Array = एक जैसी data type की values रखने वाला, memory-efficient container।

इस article में आपने सीखा कि Python Array क्या है, array module से इसे कैसे import करते हैं, Type Code क्या होता है, Array और List में क्या फर्क है, और append(), insert(), remove(), pop(), len(), in जैसे common operations कैसे इस्तेमाल होते हैं।

Array उन जगहों के लिए उपयोगी है जहाँ बड़ी मात्रा में एक जैसी numeric values को efficient तरीके से रखना हो। अब ऊपर दिया गया coding challenge खुद अपने Online Editor में solve करें।

Related Articles

🧑‍💻 Python Coding Lab

Python code likho, run karo aur practice karo — directly browser mein.