+ 1
Please I need help to understand tuples in Python
Without removing the + concatenation operator, what must I change to get this output: (-1, 0, 1 âbananasâ) tup11 = (-1, 0, 1) tup12 = (âbananasâ) tup13 = tup11 + tup12
8 Respostas
+ 4
All you need to do is to change structure to list then back it to tuple:
print(tuple(list(tup11)+list(tup12)))
or just
tup12=('banana',)
now print(tup11+tup12)
+ 1
Amirreza Hashemi
Thanx bruh!
+ 1
Amirreza Hashemi
I tried the second example you gave and itâs giving me an error
tup11 = (-1, 0, 1)
tup12 = (âbananas',)
print(tup11 + tup12)
+ 1
tup11 = (-1, 0, 1)
tup12 = ('bananas',)
print(tup11 + tup12)
#now use
+ 1
Amirreza Hashemi thanx it worked,
just to clarify i donât really need to convert it to a list and then back to a tuple?
+ 1
Jenkins no you don't just all you need is to change the tup12 data type because In your example tup12 is a string but if you want to plus them you should change tup12 Data type to tuple
+ 1
Amirreza Hashemi
Understood! Thank you for everything
+ 1
Amirreza Hashemi
Good explication.
Jenkins can also put this code(I was try)
tup11 = [-1, 0, 1]
tup12 = ["bananas"]
tup13 = tup11 + tup12
print(tuple(tup13)