数字中整数与浮点数的使用,以及将非字符串值转为字符串(使用str()函数)
#! /usr/bin/env python
# -*- coding:utf-8 -*-
'''
@Author:gcan
@Email:1528667112@qq.com
@Site:http://www.gcan.top
@File:number.py
@Software:PyCharm
@Date:2018-04-10 21:12:45
@Version:1.0.0
'''
# 整数
# 加减乘除
print(1+2)
print(1-2)
print(1*2)
print(1/2)
# 乘方
print(3**3) #27
# 运算次序
print(3*(2+8))
# 浮点数
# python将带小数点的数都称为浮点数
print(0.1+0.2)
print(0.1*0.2)
# 结果包含的小数位数可能是不固定的
# 使用str函数避免类型错误
age = 23
# message = "Happy "+age+"rd Birthday"
# print(message)
# 会报如下错误
# TypeError: must be str, not int
message = "Happy "+str(age)+"rd Birthday"
print(message)
# str()函数将非字符串值转为字符串
返回数据
3
-1
2
0.5
27
30
0.30000000000000004
0.020000000000000004
Happy 23rd Birthday
网友评论