Python基本输出语句/输入语句/变量解析

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

 print输入语句

input接收的值会转化为字符型,int()可将值转化为整型数据,float()将值转化为浮点型数据

# -*- 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)

"""运行结果"""
请输入姓名: lee
lee
<type 'str'>
请输入年龄: 13
<type 'int'>
14
请输入体重: 40.22
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

 

posted @ 2018-01-26 23:39  LEerNH  阅读(9718)  评论(0编辑  收藏  举报