Home »
Python
Empty tuple creation in Python
Python | empty tuple: Here, we are going to learn how to create an empty tuple in Python programming language?
Submitted by IncludeHelp, on April 08, 2020
Python | empty tuple
In python, we can also create a tuple without having any element. An empty tuple is created using a pair of round brackets, ().
Syntax:
tuple_name = ()
Example 1:
# Python empty tuple creation`
tuple1 = ()
# printing tuple
print("tuple1: ", tuple1)
# printing length
print("len(tuple1): ", len(tuple1))
# printing type
print("type(tuple1): ", type(tuple1))
Output
tuple1: ()
len(tuple1): 0
type(tuple1): <class 'tuple'>
Example 2:
We can also create an empty tuple by initializing the tuple with tuple() – generally this method is used to clear/reinitialize the tuple.
# Python empty tuple creation`
tuple1 = tuple()
# printing tuple
print("tuple1: ", tuple1)
# printing length
print("len(tuple1): ", len(tuple1))
# printing type
print("type(tuple1): ", type(tuple1))
print()
# non-empty tuple
tuple2 = (10, 20, 30, 40, 50)
# printing original tuple
print("tuple2: ", tuple2)
print()
# reinitialize
tuple2 = tuple()
print("After reinitialize...")
# printing tuple
print("tuple2: ", tuple2)
# printing length
print("len(tuple2): ", len(tuple2))
# printing type
print("type(tuple2): ", type(tuple2))
Output
tuple1: ()
len(tuple1): 0
type(tuple1): <class 'tuple'>
tuple2: (10, 20, 30, 40, 50)
After reinitialize...
tuple2: ()
len(tuple2): 0
type(tuple2): <class 'tuple'>
ADVERTISEMENT
ADVERTISEMENT