Answer the question
In order to leave comments, you need to log in
Why does Python wrap list elements in tuples?
Python wraps each list element followed by a comma into a tuple.
fio = {},
age = {},
date = {},
diagnoz = {}
columns = [
fio,
age,
date,
diagnoz,
]
print(columns)
[({},), ({},), ({},), {}]
TypeError: 'tuple' object does not support item assignment
Answer the question
In order to leave comments, you need to log in
No commas are needed in the first three lines.
A newline is already a sufficient instruction separator.
A comma is not used to separate instructions, only to separate elements in different sequences. It should be used inside brackets (either round, or square, or curly). If you use a comma without parentheses, then the interpreter assumes parentheses (i.e., a tuple) are implied.
Those. you need to write like this:
fio = {}
age = {}
date = {}
diagnoz = {}
By the way, the diagnoz variable - are you writing some kind of medical system? I just work in a medical center myself :))
Because the record
x = ('string',)
y = (1,)
x = 'string',
y = 1,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question