标签:proc mat 方法 数组 默认 格式化 source bsp 例子
用户交互(input)
username =input("usernam:
e")
password =input("password:")
print(username,password)
运行后,提示输入“username”和“password”, 输入后打印“username”和“password”。
name = input("name:")
age = input("age:")
salary = input("salary:")
info=‘‘‘
-----info of‘‘‘+name+‘‘‘-----
name:‘‘‘+name+‘‘‘
age:‘‘‘+age+‘‘‘
salary:‘‘‘+salary
print(info)
%s或者%d %对应一个占位符号,要一一对应。s代表string,d代表数字,%f代表浮点数。默认所有的输入都是string。
name = input("name:")
age = input("age:")
salary = input("salary:")
info=‘‘‘
-----info of %s----
name:%s
age:%s
salary:%s
‘‘‘%(name,name,age,salary)
print(info)
运行结果:
-----info of xx----
name:xx
age:hh
salary:hh
官方建议的用户使用方法。
name = input("name:")
age = input("age:")
salary = input("salary:")
info3 = ‘‘‘
---info3 of {_name} ----
name: {_name}
age: {_age}
salary: {_salary}
‘‘‘.format(_name=name,
_age=age,
_salary=salary)
print(info3)
运行结果如下:
name:LAI
age:27
salary:10000
---info3 of cathy ----
name: LAI
age: 27
salary: 10000
name = input("name")
age = input("age")
salary = input("salary")
info4 = ‘‘‘
---info4 of {0} ----
name: {0}
age: {1}
salary: {2}
‘‘‘.format(name, age, salary)
print(info4)
运行结果如下:
name:LAI
age:27
salary:15000
---info4 of cathy ----
name:LAI
age: 27
salary: 15000
上诉例子,密码是可见的,怎么让密码不可见了,有个模块getpass
import getpass
username = input("username:")
password = getpass.getpass("password")
print(username, password)
标签:proc mat 方法 数组 默认 格式化 source bsp 例子
原文地址:https://www.cnblogs.com/scau8888/p/10090630.html