Argv - String into Integer

后端 未结 3 1532
一生所求
一生所求 2020-12-10 13:35

I\'m pretty new at python and I\'ve been playing with argv. I wrote this simple program here and getting an error that says :

TypeError: %d format: a

3条回答
  •  孤城傲影
    2020-12-10 14:31

    sys.argv is indeed a list of strings. Use the int() function to turn a string to a number, provided the string can be converted.

    You need to assign the result, however:

    num1 = int(argv[1])
    num2 = int(argv[2])
    

    or simply use:

    num1, num2 = int(num1), int(num2)
    

    You did call int() but ignored the return value.

提交回复
热议问题