mirror of
https://github.com/Fechin/reference.git
synced 2026-11-20 21:23:11 +03:00
1 file changed
+24
@@ -219,6 +219,30 @@ See: [Lists](#python-lists)
|
||||
```python
|
||||
my_tuple = (1, 2, 3)
|
||||
my_tuple = tuple((1, 2, 3))
|
||||
|
||||
tupla = (1, 2, 3, 'python')
|
||||
|
||||
print(tupla[0]) # Output: 1
|
||||
print(tupla.count(1)) # Count occurrences
|
||||
print(tupla.index(2)) # Find index
|
||||
|
||||
tupla1 = (1, 2, 3)
|
||||
tupla2 = ('a', 'b')
|
||||
|
||||
len(tuple) → Returns the number of elements.
|
||||
in → Checks if an element exists in the tuple.
|
||||
Concatenation (+) → Combines two tuples.
|
||||
Repetition (*) → Repeats a tuple.
|
||||
Slicing (tuple[start:end]) → Extracts a subtuple.
|
||||
|
||||
print(len(tupla1)) # Output: 3
|
||||
print(2 in tupla1) # Output: True
|
||||
print(tupla1 + tupla2) # Output: (1, 2, 3, 'a', 'b')
|
||||
print(tupla1[1:]) # Output: (2, 3)
|
||||
|
||||
# unpacking
|
||||
a, b, c, d = tupla # Each value goes into a variable
|
||||
|
||||
```
|
||||
|
||||
Similar to List but immutable
|
||||
|
||||
Reference in new issue
Block a user