六、代码注释:
1.注释,单行#; 多行三个引号;
2.3个引号可以打印多行
msg=''' name2=name print("My name is ",name,name2) name = paochege '''
3如果打印单行,用单引号或者双引号,都可以;
msg = "name2 = $name" msg= " I'm alex li "
七、用户输入
name= input ("name:") age= input("age:") job=input("job:") salary=input("salary:") info=''' -------------info of %s----------------- Name:%s Age:%s Job:%s Salary:%s ''' %(name,name,age,job,salary) print (info)
类型转换,input输入默认是字符串;
name= input("name:") age= int(input("age:")) #integer print( type(age), type(str(age) ) ) 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)
python2中的raw_input=pyth3下的input;
格式化输出的另外一种方式
name=input("name:") age=input("age:") job=input("job") salary=input("salary") info2=''' -------------------info of {_name}-------------- Name:{_name} Age:{_age} Job:{_job} Salary:{_salary} '''.farmat(_name=name, _age=age, _job=job, _salary=salary ) print info2