方法1: 字符串的拼接
方法2: %s占位符
name = input("name:") age = int(input("age:")) #integer转成数字 job = input("job:") salary = input("salary:") info =‘‘‘ -----------info of %s --------- name: %s age: %d job: %s salary: %s ‘‘‘%(name, name,age, job,salary) print(info)
方法3: format的使用(推荐)
name = input("name:") age = int(input("age:")) #integer转成数字 job = input("job:") salary = input("salary:") info =‘‘‘ -----------info of {_name} --------- name:{_name} age:{_age} job:{_job} salary:{_salary} ‘‘‘.format(_name=name, _age=age, _job=job, _salary=salary) print(info)
or
name = input("name:") age = int(input("age:")) #integer转成数字 job = input("job:") salary = input("salary:") info2 =‘‘‘ -----------info2 of {0} --------- name: {0} age: {1} job: {2} salary: {3} ‘‘‘.format(name, age, job,salary) print(info2)
import getpass #getpass是个standard moduel, 在pycharm中不好使。 _username = ‘alex‘ _password = ‘abc123‘ username = input("username:") password = input("password:") #password = getpass.getpass("password") # 如果要秘闻psw,就用这个 if _username == username and _password == password: print("welcome user {name} login...".format(name=username)) else: print ("invalid username or password")
Python 基础 - Day 1 Learning Note - 用户交互Interaction程序
原文:http://www.cnblogs.com/lg100lg100/p/7112997.html