List
- A
List
hija firxa dinamika fi Python, li tippermettilek taħżen valuri differenti multipli, u l-elementi jistgħu jinbidlu wara l-inizjalizzazzjoni. - Biex tiddikjara a
List
, uża parentesi kwadri[]
.
Eżempju:
# Declare a List containing integers
numbers = [1, 2, 3, 4, 5]
# Access and print elements in the List
print(numbers[0]) # Output: 1
print(numbers[2]) # Output: 3
# Modify the value of an element in the List
numbers[1] = 10
print(numbers) # Output: [1, 10, 3, 4, 5]
Tuple
- A
Tuple
hija struttura ta' data immutabbli fi Python, spiss użata biex tipproteġi d-data milli tinbidel wara l-inizjalizzazzjoni. - Biex tiddikjara a
Tuple
, uża l-parentesi()
.
Eżempju:
# Declare a Tuple containing information of a student
student_info =('John', 25, 'Male', 'New York')
# Access and print elements in the Tuple
print(student_info[0]) # Output: John
print(student_info[2]) # Output: Male
Set
- A
Set
hija struttura tad-dejta li ma fihax elementi duplikati u m'għandha l-ebda ordni. - Biex tiddikjara a
Set
, uża ċineg kaboċċi{}
jew il-set()
funzjoni.
Eżempju:
# Declare a Set containing colors
colors = {'red', 'green', 'blue', 'red', 'yellow'}
# Print the Set to check duplicate elements are removed
print(colors) # Output: {'red', 'green', 'blue', 'yellow'}
Dictionary
- A
Dictionary
hija struttura tad-dejta mhux ordnata li taħżen l-informazzjoni f'pari ewlenin-valur. - Biex tiddikjara
Dictionary
, uża ċineg kaboċċi{}
u ssepara kull par ta' valur-ċavetta b'kolon:
.
Eżempju :
# Declare a Dictionary containing information of a person
person = {'name': 'John', 'age': 30, 'city': 'New York'}
# Access and print values from the Dictionary
print(person['name']) # Output: John
print(person['age']) # Output: 30
# Modify the value of a key in the Dictionary
person['city'] = 'Los Angeles'
print(person) # Output: {'name': 'John', 'age': 30, 'city': 'Los Angeles'}
Dawn l-istrutturi tad-dejta jippermettu lill-programmaturi jimmanipulaw u jipproċessaw id-dejta b'mod flessibbli fi Python, adattat għal diversi xenarji u skopijiet ta 'programmazzjoni.