码迷,mamicode.com
首页 > 编程语言 > 详细

python基础 Day01 练习题

时间:2017-01-07 13:01:29      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:for   use   art   tar   ges   pycha   pyc   格式   word   

1 字符串格式化

技术分享
 1 #!/urs/bin/env python
 2 
 3 name = input("Name: ")
 4 age = int(input("Age: "))
 5 job = input("Job: ")
 6 salary = input("Salary: ")
 7 
 8 info1 = """
 9 
10 ----------- info1 of %s ---------
11 name: %s
12 age: %s
13 job: %s
14 Salary: %s
15 """ % (name, name, age, job, salary)
16 
17 print(info1)
18 
19 info2 = """
20 
21 ----------- info2 of {_name} ----
22 Name: {_name}
23 Age: {_age}
24 Job: {_job}
25 Salary: {_salary}
26 """.format(_name=name,
27            _age=age,
28            _job=job,
29            _salary=salary)
30 
31 print(info2)
32 
33 info3 = """
34 
35 ------ info3 of {0} -------
36 Name: {0}
37 Age: {1}
38 Job: {2}
39 Salary: {3}
40 """.format(name, age, job, salary)
41 
42 print(info3)
View Code

2 密码非明文显示

技术分享
1 #!/urs/bin/env python
2 # -*- coding:utf-8 -*-
3 
4 import getpass
5 username = input("username:")
6 password = getpass.getpass("password:")
7 
8 print(username)
9 print(password)
View Code

注在Pycharm中不可以,在命令行模式运行:python xxx.py可以

 

python基础 Day01 练习题

标签:for   use   art   tar   ges   pycha   pyc   格式   word   

原文地址:http://www.cnblogs.com/todayisafineday/p/6259020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!