Merge pull request #663 from andersonpablo/patch-1

Update python.md
This commit is contained in:
Fechin authored and GitHub committed 2025-05-01 08:05:38 +08:00
commit 195d3fc24a
1 file changed
+24
+24
View File
@@ -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