Home > OS >  Converting Multiple string inputs to int
Converting Multiple string inputs to int

Time:11-03

I'm trying to convert a, b, c, d to integers, but after I've tried doing this they still come up as strings. I've tried using a loop instead of map, but that didn't work either.

inputs = input()
split_input = inputs.split()
a, b, c, d = split_input
split_input = list(map(int, split_input))

CodePudding user response:

Just swap the last 2 lines:

split_input = list(map(int, split_input))
a, b, c, d = split_input

Unless you need split_input later on, you don't need the list conversion at all:

split_input = map(int, split_input)
a, b, c, d = split_input
# OR in fact simply
a, b, c, d = map(int, split_input)
  • Related