diff --git a/source/_posts/python.md b/source/_posts/python.md index 6f04a7a..faba4bd 100644 --- a/source/_posts/python.md +++ b/source/_posts/python.md @@ -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