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

How to declare variables from an input() with different class ( int and str)

iLig1, iCol1 , iLig2 , iCol2 , carac = map(int, input ().split ())

hello I try to get this ligne of input in my code right, I get 5 variables from an input that look like this:

1 12 7 14 u

how can I declare the last one as a str properly,
I tried to consider them all as str and convert the 4 first as int but I cannot interpret str as int (you know..)

Thank you for your help !

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

>Solution :

You can use the Iterable Unpacking : (*).

# we suppose input is -> 1 2 3 4 u
>>> (*i, j) = input().split()

>>> print(i)
['1', '2', '3', '4']

>>> print(j)
u

>>> list(map(int, i))
[1, 2, 3, 4]
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