admin管理员组文章数量:1589747
python -- 用户交互interaction
input() 和format()用法
name = input("User Name:\n")
password = input("User Password:\n")
age = int(input("User Age:\n"))
# 建议使用format这样,取代%的用法
user_info = '''
Name:{0}
Password:{1}
Age:{2}'''.format(name,password,age)
print(user_info)
getpass方法
输入密码是,如果输入密码时,需要可见的话,需要利用getpass模块中的getpass方法。
import getpass
name = input("User Name:\n")
# 在Pycharm里面不能使用,在cmd里可以
password = getpass.getpass("User Password:\n")
写在后面
- 使用type(),表示数据类型
a = "Gao"
# 这里就是用来调用type()函数
b = type(a)
print(b)
- 使用int(),将字符串转换成整型
a = "13"
# a一定要是一个数字形式的字符串,不然会报错
b = int(a)
print(b)
- 使用str(),转换成字符串
a = 13
b = str(a)
c = ['name',11,'age',{11:22}]
d = str(c)
print(b,d)
- 字符串拼接,建议使用format格式,使用format是在内存里开辟一个内存空间,而使用加号+做字符串拼接,却是在内存里开辟多个内存空间,效率==低下==。
转载于:https://wwwblogs/gzz041/p/7061836.html
本文标签: 用户PythonInteraction
版权声明:本文标题:python -- 用户交互interaction 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728076472a1144542.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论