Python beginner's question

Asked 2 years ago, Updated 2 years ago, 16 views

Problem) I tried to add content to the following sequence material, but an error occurred. How can I change the contents of the code to add the contents of the sequence data?

'''

len(s)

3

s.append(4)

Traceback (most recent call last):

File "", line 1, in

s.append(4)

AttributeError: 'tuple' object has no attribute 'append'

'''

I don't know why the error occurred while solving this problem. You don't have to tell me the answer, so I just want to know the reason for the error!

python

2022-09-22 20:21

3 Answers

Tuples with brackets ( ) cannot modify, delete, or add values. To add a value with append, you can make a list with square brackets [].


2022-09-22 20:21

The error code tells you the correct answer.

AttributeError: 'tuple' object has no attribute 'append'

The 'tuple' type data does not provide a built-in method called append.

I think you need to learn about Python's Primary Data Type.

See Python Document below for more information.

https://docs.python.org/3/library/stdtypes.html


2022-09-22 20:21

Simply put, the error is "No tuples." (Tuples do not have append function.) I don't know what value is in s because the code is truncated, but it should be s = [value 1, value 2....] The conclusion is that s must be in the form of an array that contains the value in [ ].


2022-09-22 20:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.