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'>






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.








Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.