栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 前沿技术 > 大数据 > 大数据系统

Python 用户输入 --笔记

Python 用户输入 --笔记

input()        函数接收输入字符

int()            获取数值输入

stu = input("please input: ")
print("output: ",stu)
a = "sdf gret try w35r re"
a += "please input:"
stu = input(a)          #如果提示字符太长,通过赋值变量输出
print("output: ",stu)

stu = int(input("please input digit: "))   #只能够输入数字,否则会出错
print("output: ",stu)
please input: rweq
output:  rweq
sdf gret try w35r replease input:greggre
output:  greggre
please input digit: 3242321
output:  3242321


#错误实例
please input: ew
output:  ew
sdf gret try w35r replease input:rew
output:  rew
please input digit: erw
Traceback (most recent call last):
  File "/Users/sw-diag/Desktop/SW-USERS/Lin/pythonProject/main.py", line 122, in 
    stu = int(input("please input digit: "))   #只能够输入数字,否则会出错
ValueError: invalid literal for int() with base 10: 'erw'

转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/278485.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号