What is the difference between
JavaScript
x
2
1
("a")
2
and
JavaScript
1
2
1
("a",)
2
I noticed that for example mysql wrapper parameters formatting doesn’t work with the first case, it must end with comma.
JavaScript
1
2
1
cursorA.execute(query, (url,))
2
Advertisement
Answer
if you write only one element in parentheses (), the parentheses () are ignored and not considered a tuple.
JavaScript
1
4
1
x = ("a")
2
3
print(type(x))
4
output: str
to generate a one-element tuple, a comma ,
is needed at the end.
JavaScript
1
4
1
x = ("a", )
2
3
print(type(x))
4
ouput : tuple