logo-MindMajix
PostPythonPython
k
kumar san

Posted on 21st July 2024|19 views

0
votes

Python Append To Tuple

How to append elements in python tuple?

1 answers
Answers
P
sri kanth

Posted on 21st July 2024| views

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
Name
Course *
Email *
Phone Number