Types of Sequence Data Types :-
Python में Sequence Data Types ऐसे data types हैं जिनमें multiple elements या values को एक निश्चित क्रम (order) में store किया जाता है। Python में मुख्य Sequence Data Types निम्नलिखित हैं:
- String (str)
- List (list)
- Tuple (tuple)
- Range (range)
1. String (str) :-
String characters का एक ordered sequence है। इसका उपयोग text, words, sentences आदि को store करने के लिए किया जाता है।
Example:-
name = "Python"
print(name[0])
print(name[3])
Output:-
P
h
Because:-
Python में characters के index इस प्रकार हैं:
Character : P y t h o n
Index : 0 1 2 3 4 5
English:
A String is an ordered sequence of characters. It is used to store text and can be accessed using indexing.
Important: String Immutable होती है, अर्थात बनने के बाद इसके individual characters को directly change नहीं किया जा सकता।
2. List (list) :-
List एक ordered collection of elements है। इसमें अलग-अलग प्रकार के multiple values को एक साथ store किया जा सकता है।
Example:-
student = ["Rahul", 20, "O Level", 85.5]
print(student[0])
print(student[2])
Output:-
Rahul
O Level
Because:-
List में elements के index होते हैं:
Element : Rahul 20 O Level 85.5
Index : 0 1 2 3
English:
A List is an ordered and mutable collection that can store multiple elements of different data types.
Important: List Mutable होती है, अर्थात इसके elements को बाद में change किया जा सकता है।
Example:-
numbers = [10, 20, 30]
numbers[1] = 50
print(numbers)
Output:-
[10, 50, 30]
3. Tuple (tuple) :-
Tuple भी एक ordered collection है जिसमें multiple elements को store किया जाता है।
Example:-
numbers = (10, 20, 30, 40)
print(numbers[0])
print(numbers[2])
Output:-
10
30
Because:-
Tuple में भी elements index के द्वारा access किए जा सकते हैं।
Element : 10 20 30 40
Index : 0 1 2 3
English:
A Tuple is an ordered and immutable collection of elements.
Important: Tuple Immutable होता है, इसलिए इसके elements को बनने के बाद directly change नहीं किया जा सकता।
Example:-
numbers = (10, 20, 30)
# numbers[1] = 50
ऊपर दिया गया assignment करने पर TypeError आएगा क्योंकि Tuple immutable होता है।
4. Range (range) :-
Range एक ऐसा Sequence Data Type है जिसका उपयोग numbers के sequence को represent करने के लिए किया जाता है।
यह विशेष रूप से for loop में बहुत अधिक उपयोग किया जाता है।
Example:-
numbers = range(1, 6)
for n in numbers:
print(n)
Output:-
1
2
3
4
5
Because:-
range(1, 6)
1 से शुरू होता है और 6 से पहले तक numbers generate करता है।
अर्थात:
1, 2, 3, 4, 5
English:
The range type represents an immutable sequence of numbers. It is commonly used with for loops.