首页 > 编程语言 > 详细

Python基础 input()的使用

时间:2019-06-12 02:54:00      阅读:187      评论:0      收藏:0      [点我收藏+]
input()函数用于读取标准输入
注意:input函数的返回值类型为字符串

        >>> num=input("Please input a number:")
        Please input a number:32
        >>> type(num)
        <class ‘str‘>

        >>> num1=input("Please input the number1:")
        Please input the number1:5
        >>> num2=input("Please input the number2:")
        >>> print("number1 + number2 =",(num1+num2))
        number1 + number2 = 53
        >>> print("number1 + number2 =",(int(num1)+int(num2)))
        number1 + number2 = 8
        >>> cus=input("Please input the custom name:")
        Please input the custom name:Tom
        >>> cid=input("Please input the custom ID:")
        Please input the custom ID:001
        >>> cus_info=‘‘‘
                        custom_name:{0}
                        custom_id:{1}
                        ‘‘‘.format(cus,cid)
        >>> print(cus_info)
        custom_name:Tom
        custom_id:001

Python基础 input()的使用

原文:https://blog.51cto.com/5279100/2407457

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!