How can I convert a string to an int in Python?

前端 未结 8 1483
北恋
北恋 2020-11-27 21:35

The output I\'m getting for my little example app is the following:

Welcome to the Calculator!
Please choose what you\'d like to do:
0: Addition
1: Subtracti         


        
8条回答
  •  时光说笑
    2020-11-27 22:21

    >>> a = "123"
    >>> int(a)
    123
    

    Here's some freebie code:

    def getTwoNumbers():
        numberA = raw_input("Enter your first number: ")
        numberB = raw_input("Enter your second number: ")
        return int(numberA), int(numberB)
    

提交回复
热议问题