List
- A
Listje dinamično polje v Python, ki vam omogoča shranjevanje več različnih vrednosti, elemente pa je mogoče spremeniti po inicializaciji. - Če želite deklarirati
List, uporabite oglate oklepaje[].
primer:
# 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
Tupleje nespremenljiva podatkovna struktura v Python, ki se pogosto uporablja za zaščito podatkov pred spreminjanjem po inicializaciji. - Če želite deklarirati
Tuple, uporabite oklepaje().
primer:
# 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
Setje podatkovna struktura, ki ne vsebuje podvojenih elementov in nima vrstnega reda. - Če želite deklarirati
Set, uporabite zavite oklepaje{}aliset()funkcijo.
primer:
# 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
Dictionaryje neurejena podatkovna struktura, ki shranjuje informacije v parih ključ-vrednost. - Če želite deklarirati
Dictionary, uporabite zavite oklepaje{}in ločite vsak par ključ-vrednost z dvopičjem:.
primer :
# 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'}
Te podatkovne strukture programerjem omogočajo fleksibilno upravljanje in obdelavo podatkov v Python, kar je primerno za različne scenarije in namene programiranja.

