Python Forum
tuple - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: tuple (/thread-16281.html)



tuple - veysel - Feb-21-2019

hello everyone, i have q question to you

s=("hello",)


b=s+tuple("veysel",)
print(b)
it prints ('hello', 'v', 'e', 'y', 's', 'e', 'l') but i am waiting ('hello','veysel') is only way to do that like in following ?
s=("hello",)
a="veysel",
b=s+a
print(b) 



RE: tuple - buran - Feb-21-2019

tuple("veysel",) is same as tuple("veysel"). When you pass str as argument to tuple() function it returns tuple of chars:

>>> tuple("veysel")
('v', 'e', 'y', 's', 'e', 'l')
>>>
effectively first snippet is
s=("hello",)
b=s+('v', 'e', 'y', 's', 'e', 'l')
print(b)
In the second example, both s and a are tuples. Note that a is tuple, because of the comma at the end:
>>> a = 'veysel',
>>> type(a)
<class 'tuple'>
>>>



RE: tuple - veysel - Feb-21-2019

Thank you for help i understand and 10 minutes ago i found that;
s=("hello",)

b=s+tuple(("veysel",))

>>print(b)

('hello', 'veysel')
this is what i search and actually this is same as what you say


RE: tuple - buran - Feb-21-2019

(Feb-21-2019, 10:05 AM)veysel Wrote: b=s+tuple(("veysel",))

you don't need tuple() here, because ("veysel",) is already a ruple

(Feb-21-2019, 10:05 AM)veysel Wrote: this is what i search and actually this is same as what you say

Do you care to elaborate further. This looks like you try to do something, but I guess if we know your ultimate goal we can suggest a better approach


RE: tuple - veysel - Feb-21-2019

thank you, now i understand my fault and i correct my faults like;

a=("veysel",)

>>print(a)
('veysel',)

a=a+("olgun",)

>>print(a)
('veysel', 'olgun')