python 数据输入(input语句)

1.input

1.1 input 输入格式

①print("请告诉我你是谁:") 
②name = input()
print("我知道了,你是%s" % name)
"""
请告诉我你是谁:
黎明
我知道了,你是黎明
"""
①,②两句等同于 `name = input("请告诉我你是谁?")`

1.2 input默认接收类型都是字符串

#  输入数字类型
num = input("please input the key numbers:")
print("key nembers的数据类型是:%s" % type(num))
"""
运行结果:
please input the key numbers:12345
key nembers的数据类型是:<class 'str'>
"""

1.2.1即使是数字也当成了字符串处理,那需要是数字的时候怎么办?

#  数据类型转换
num = input("please input the key numbers:")
num = int(num) #  类型转换
print("key nembers的数据类型是:%s" % type(num))
"""
运行结果:
please input the key numbers:123456
key nembers的数据类型是:<class 'int'>
"""
posted @ 2022-10-04 20:56  Dalier-!  阅读(579)  评论(0)    收藏  举报