print 格式化输出
print 输入语句
# -*- coding: utf-8 -*-
# print (format(val, 'm,n'))
# val:值 format_modifier:输出占位 m, 精度 n
print (format(12.3456,'6.2f' ))
12.35
print (format(12.3456,'6.3f' ))
12.346
print (format(12.3456,'6.6f' ))
12.345600
print (format(12.3456,'6.0f' ))
12
input 接收的值会转化为字符型,int()可将值转化为整型数据,float()将值转化为浮点型数据
请输入姓名: lee
# -*- coding: utf-8 -*-
name = raw_input('请输入姓名:')
print name
print type(name)
age = raw_input('请输入年龄:')
age = int(age)
print type(age)
age = age + 1
print age
weight = float(raw_input('请输入体重:'))
print weight
print type(weight)
"""运行结果"""
请输入年龄: 13
lee
<type 'str'>
请输入体重: 40.22
<type 'int'>
14
变量解析
40.22
<type 'float'>
变量改变只改变指向地址不改变指向内容
# -*- coding: utf-8 -*-
x = 13
print x, id(x)
y = 12
print y, id(y)
x = y
print x, id(x)
z = 13
print z, id(z)
"""运行结果"""
13 73496064
12 73496076
12 73496076
13 73496064
来源: http://www.bubuko.com/infodetail-2476498.html