# Python【常用的数据类型】

2019/07/21 21:37

int,  float,  string

----------------------------------------

>>> Chinese = '镜像世界'
>>> English = "mirror world"
>>> number = "666"
>>> symbol = '''科A!@'''
>>> mixture = '镜像世界mirror world666科A!@'
>>> print(Chinese)

>>> print(English)
mirror world
>>> print(number)
666
>>> print(symbol)

>>> print(mixture)

-------------------------------------------

-------------------------------------------

>>> print(0.55+0.3)
0.8500000000000001   #不是0.85

————————————————————
*四则运算*

>>> print(499*561+10620-365)
290194
>>> print((5025-525)/100+18*17)
351.0

————————————————————
*字符串的拼接*

————————————————————

*数据类型的查询--type()函数*

>>> number = 153
>>> print(type(number))
<class 'int'>

str()、 int()和float()

>>> magic = '水仙花数'
>>> action = '是'
>>> unit = '个'
>>> expression = '＝1x1x1+5x5x5+3x3x3'
>>> number = 153

>>> print(str(number)+expression+action+unit+magic)
153＝1x1x1+5x5x5+3x3x3是个水仙花数

>>> print('153'+expression+action+unit+magic)
153＝1x1x1+5x5x5+3x3x3是个水仙花数

————————————————————————
int()函数
#只有符合整数规范的字符串类数据，才能被int()强制转换

>>> number1 = '6'
>>> number2 = '1'
>>> print(int(number1)+int(number2))
7

print(int('3.8')) #另外小数形式的字符串也不能强制转换

print(int(3.8)) #int()函数会做取整处理，小数位直接抹零
3
——————————————————
float()函数

>>> height = 188.0
>>> weight = 180.0
>>> age = '89'
>>> print(float(height))
188.0
>>> print(float(weight))
180.0
>>> print(float(age))
89.0

*数据多次转换*

>>> slogan = '脸黑怪我咯'
>>> number = '7.8'
>>> unit = '张'
>>> sentence = '蓝票一个SSR都没有'
>>> print(slogan+str(int(float(number)))+unit+sentence)

0
0 收藏

0 评论
0 收藏
0