Assign string elements to variables

I have some strings with 3 elements, such as '010','101'… I’m trying to assign the elements of those strings to some variables, like a,b,c. I could do that through a,b,c = "0 1 0".split(). However, if there’s no spacing in my string, how can I assign those values?

>Solution :

You can do it just like similar to the Tuple Unpacking, like

a, b, c = '101'

Printing them will give you what you expect (in string format)

print(a, b, c, type(a))


1 0 1 <class 'str'>

Tell me if its not working…

Leave a Reply