Javatpoint Logo
Javatpoint Logo

Empty Tuple Python

What are Tuples in Python?

A tuple is an arrangement of immutable, ordered items. Since both tuples and Python lists are sequences, they are analogous. Tuples and lists, however, vary since we cannot edit tuples; however, we can change lists after initializing them. Additionally, we build tuples using parentheses, whereas we make lists using square brackets.

A tuple is created by putting different values inside the parenthesis, separated by commas. For example,

Example of a Tuple

You can create an empty tuple object by giving no elements in parentheses in an assignment statement. The built-in function of Python, tuple(), also creates a blank tuple object when it is called without any arguments.

Code

Output:

()
()

How to Check Empty Tuple in Python?

You can generate an empty tuple by placing no components in parenthesis in the assignment phrase. The built-in method tuple() also creates an empty tuple object when called without passing any arguments.

Using the not Operator

Code

Output:

The given tuple is empty
()
Using the len() Function

Code

Output:

The given tuple is empty
()

An empty tuple called "my tuple" was initialized in the instance above. The length of the tuple was then determined using the built-in Python function len() and saved in the variable name "len_tuple." The length of my_tuple was then checked using an if statement to see if it equaled zero.

The tuple is considered empty if the condition stands true. The tuple is considered as not empty otherwise.

Changing a Tuple to Empty Tuple

Let's suppose we have a tuple that has elements in it. We need to change it to an empty tuple. Let us see how to do this.

Code

Output:

Original tuple:  ('a', 3, 'b', 'c', 'd', 'e', 'g', 's', 'k', 'v', 'l')
After removing a single item:-  ('a', 3, 'b', 'c', 'e', 'g', 's', 'k', 'v', 'l')
New empty tuple:-  ()

Comparing with Another Empty Tuple

We will see the results if we compare two tuples

Code

Output:

my_tuple1 is not empty






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA