#交互式输出
1
2
3
4
5
6
7
8
9
10
|
#!/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 password?admin@
1234
xcn admin@
1234
|
#交互式格式输出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#!/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)类型
1
2
3
4
|
#!/usr/bin/env python
# -*- coding:utf-8 -*-
age
=
int
(
input
(
"age:"
))
print
(
type
(age),
type
(
str
(age)))
|
本文转自 baishuchao 51CTO博客,原文链接:http://blog.51cto.com/baishuchao/1932890