1.python打印hello world!
#!/usr/bin/env python print("hello world!")
2.实现用户名密码输入:
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- ##设置代码字符编码 3 username = input("username:") 4 password = input("password:") 5 print(username,password)
3.实现密码密文输入:
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 import getpass ##导入密码加密模块 4 username = input("username:") 5 password = getpass.getpass("password:") 6 print(username,password)
4.模块介绍
1.注释: 当行注释:# 多行注释:'''****'''
1 range(10):次数区间,最多10次 2 getpass:密码加密 3 break: 终止全部执行操作 4 continue:跳过本次操作,继续开始新的操作
1 数据类型转换: 2 3 int (type (age)) 字符串改为数字 4 str(type(age)) 数字改为字符串
5.格式化输出
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 name = input("name:") 4 age = input("age:") 5 job = input("job:") 6 salary = input("salary:")
1 方案一: 2 info = ''' 3 ------- info of %s ------- 4 Name:%s 5 Age:%s 6 Job:%s 7 Salary:%s 8 ''' % (name,name,age,job,salary) 9 print(info)
1 方案二: 2 info = ''' 3 -------- info of {_name} -------- 4 Name:{_name} 5 Age:{_age} 6 Job:{_job} 7 Salary:{_salary} 8 '''.format(_name=name, 9 _age=age, 10 _job=job, 11 _salary=salary) 12 print(info)
1 方案三: 2 info = ''' 3 -------- info of {0}-------- 4 Name:{0} 5 Age:{1} 6 Job:{2} 7 Salary:{3} 8 '''.format(name,age,job,salary) 9 print(info)