×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Home » Python

Reinitializing a tuple in Python

Python | Reinitializing tuple: Here, we are going to learn about the various methods to reinitialize a tuple in Python programming language?
Submitted by IncludeHelp, on April 08, 2020

Python | Reinitializing tuple

In this tutorial, we will learn how can we reinitialize a tuple with a new set of elements/objects?

To reinitialize a tuple, we can use tuple() or a pair of round brackets (), the steps are,

  1. Reinitialize the tuple using () or tuple()
  2. Reassign the new set of objects/elements

Consider the below program,

# Reinitializing a tuple in Python

# tuple creation
x = ("Shivang", 21, "Indore", 9999867123)

# printing original tuple
print("x: ", x)
print("len(x): ", len(x))
print("type(x): ", type(x))
print()

# Reinitializing tuple using tuple()
x = tuple()
# assigning new  objects
x = (10, 20, 30, 40, 50)
print("x: ", x)
print("len(x): ", len(x))
print("type(x): ", type(x))
print()

# Reinitializing tuple using ()
x = ()
# assigning new  objects
x = ("Amit", 18, "Jaipur", 98.24, 8888888888)
print("x: ", x)
print("len(x): ", len(x))
print("type(x): ", type(x))
print()

Output

x:  ('Shivang', 21, 'Indore', 9999867123)
len(x):  4
type(x):  <class 'tuple'>

x:  (10, 20, 30, 40, 50)
len(x):  5
type(x):  <class 'tuple'>

x:  ('Amit', 18, 'Jaipur', 98.24, 8888888888)
len(x):  5
type(x):  <class 'tuple'>
Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.