Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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))

Outputs:

1 0 1 <class 'str'>

Tell me if its not working…

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading