Post

PythonPython

k
kumar san

Posted on 25th April 2024|18 views

0
votes

Python Append To Tuple

How to append elements in python tuple?

Answers
P
sri kanth

Posted on 25th April 2024

Python tuple is an immutable object which means we cannot change it or we cannot append it, but there is an alternative way, by using the built-in list() function convert the tuple into the list. You can append the list objects then again convert the list object into tuple object by using tuple(). Here is the example

Tu=(10,50,20)

>>> Li=list(Tu)

>>> Li

[10, 50, 20]

>>> Li.append(80)

>>> Tu=tuple(Li)

>>> Tu

(10, 50, 20, 80)

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos