Make a cartesian product from two tuples in Python

Here is an example to make a cartesian product of two tuples in Python. python x = ('a', 'b') y = ('c', 'd') z = tuple((i, j) for i in ...

Create or declare a tuple in Python

A Python tuple is the data type containing multiple elements like a list or dictionary. All elements are separated with a comma and enclosed in ...

Convert string to tuple in Python

You can convert a Python string to a tuple using `tuple()`, a Python built-in function. python s = 'Apple' t = tuple(s) print(t) # (...

How to reverse a tuple in Python: sorted() can reverse a tuple but returns a list

You can reverse a [tuple](/python-tuple) using the Python slicing syntax. python t1 = ('A', 'B', 'C') t2 = (7,) t3 = () r1 = t1[::-1] ...

Python tuple - How to get the length of a tuple

You can get the length of a [tuple](/python-tuple) using the `len()`, a Python built-in function. python t1 = ('A', 'B', 'C') t2 = (7,) t...

Python tuple addition (concatenate tuples)

We can add Python tuples with an addition operator in the same way as numbers or strings addition. python t1 = ('A', 'B', 'C') t2 = ('D', ...

Python tuple - How to iterate the tuple and get the index in the for statement

You can iterate a [tuple](/python-tuple) in the for statement in Python. python t = (1, 2, 3, 4) for i in t: print(i) # 1 # 2 ...

A Python tuple that has only one element without a trailing comma is not a tuple

A Python tuple that has only one element without a trailing comma is not regarded a tuple. python s = ('Apple') t = (13) u = (24,) pri...

Python tuple subtraction

Python doesn't support tuple subtraction and `-` operand. python a = (5, 6, 7) b = (5, 6) c = a - b # TypeError: unsupported operand...

Python Tuple (iteration, empty tuple, length, index, addition)

A Python tuple is a ordered and immutable set of objects declared with parentheses. python a = (1, 2, 3) print(a) # (1, 2, 3) print(ty...

Python tuple unpack: What do underscores and asterisks mean in unpacking?

You can get all items of a tuple without the for or while statement. python s = ('a', 'b', 'c') x, y, z = s print(x) # a print(y) ...

Python String

Python List

Python Tuple

Python Set

Python Dictionary

Python Float

Python Decimal

Python Fraction

Python Date & Time

Python Function

Python Class

Python File

Python Built in

Python Math

Python Counter

Python Functools

Python Itertools

Python Deque

Python Tips

© Rollpie