Profile Picture

maddjester

Reputation: 0 [rate]

Joined: Feb, 2022

Last online:

Badges

badge

Etc

Send Message

Threads List
Possible Alts

Activity Feed

Replied to thread : Python Error Challenge: List vs. Tuple Misuse


You are trying to use the append method which is not supported on a tuple object.
The only methods that are supported are: count, index.

For more information:
https://www.w3schools.com/python/python_ref_tuple.asp

You can convert it to an object that supports the method like in the example below.

 

# Initializing a list

my_data = [10, 20, 30, 40, 50]

# Attempting to change the second element to 99

my_data[1] = 99

# Creating a tuple

my_tuple = (1, 2, 3, 4, 5)

# To append a new element to a tuple convert it to a list first

my_list = list(my_tuple)

my_list.append(6)

# You may then convert it back to a tuple like this

my_tuple = tuple(my_list)

print(my_tuple)