1.输出 函数 print
(1). 打印浮点数
print(format(data,'m,nf')) # format 也是一个格式打印的函数:m -->打印出的浮点数占的字符串个数,n-->小数点后保留几位(精度)
#小数点后3位,小数点前2位 正好是m的5位
print(format(12.34567,'5.3f'))
12.346
#补0
print(format(12.34567,'5.7f'))
12.3456700
#m > 值的字符数量 右对齐 前面空格
print(format(12.345,'8.2f'))
12.35
#m < 字符串的字符数量,左对齐,全部打印出
print(format(12.345,'3.2f'))
12.35
(2). 打印 % 浮点数
(2). 打印 % 数据
print(format(0.2345,'.3%')) #.k k就是小数点后面几位
23.450%
2. 输入函数 raw_input([prompt])
help(raw_input) #标准输入写入一个字符串
Help on built-in function raw_input in module __builtin__:
raw_input(...)
raw_input([prompt]) -> string
Read a string from standard input. The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled. The prompt string, if given,
is printed without a trailing newline before reading.
res = int(raw_input("plz input your age:")) #键盘输入年龄
plz input your age:25
>>> print res
25
>>> type(res)
<type 'int'>
weight = float(raw_input("plz input your weight:"))
plz input your weight:67.8
>>> print weight
67.8
>>> type(weight)
<type 'float'>