python交互式(input)
阿新 • • 發佈:2017-06-06
python交互式(input)
#交互式輸出
#!/usr/bin/env python # -*- coding:utf-8 -*- name = input("what is your name?") password = input("Please enter password?") print(name, password) 執行輸出: what is your name?xcn Please enter [email protected] xcn [email protected]
#交互式格式輸出
#!/usr/bin/env python # -*- coding:utf-8 -*- name = input("name:") age = input("age:") job = input("job:") salary = input("salary:") info = ‘‘‘ -----------info %s------------- name : %s age : %s job : %s salary : %s ‘‘‘ % (name, age, job, salary) print(info) 執行輸出: name:xcn age:20 job:12 salary:2000 -----------info xcn------------- name : 20 age : 12 job : 2000 salary : 123 #註釋: % 相當於shell 中的$ s 相當於string 字符串
#定義打印(print)類型
#!/usr/bin/env python # -*- coding:utf-8 -*- age = int(input("age:")) print(type(age), type(str(age)))
本文出自 “小菜鳥” 博客,請務必保留此出處http://baishuchao.blog.51cto.com/12918589/1932890
python交互式(input)