1. python的输入与输出
name = input("name:") 输入name,默认的类型为字符串类型 age = int(input("age:")) 强制类型转化为int类型 print(type(age)) 输出变量的类型
字符拼接输出:
#第一种格式: info = ''' ------- info of %s ------ Name:%s Age:%d Job:%s Salary:%s ''' % (name, name, age, job, salary) #第二种格式 info = "' ------info of {_name} ------ Name:{_name} Age:{_Age} Job:{_Job} Salary:{_salary} '''.format(_name = name, _age = age, _job = job, _salary = salary) #第三种格式 info = ''' ------info of {0} ------ Name:{0} Age:{1} Job:{2} Salary:{3} '''.format(name, age, job, salary)
2. 登陆时隐藏密码
import getpass passwd = getpass.getpass("passwd:")
3. 判断语句
if guess_age == age_of_oldboy: print("yes,you got it") #缩进和java的括号作用相同 break elif guess_age > age_of_oldboy: print("think smaller...") else: print("think bigger...")
4. 循环语句
4.1 for 循环
for i in range(0,10,2) print("loop", i) else: #正常(非break)结束时候执行此处代码,break结束时不执行此代码
4.2 while循环
while True:#死循环 while count < 3: else: #正常结束时执行此处代码