python知识梳理-基础(二):数据类型

python3

pycharm

一、字符串

用单引号、双引号、三引号引用起来

a='test,abc'
b="quit,wer"
c='''i love_you,name!'''
print(a,b,c)
print(type(a),type(b),type(c))

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

test,abc quit,wer i love_you,name!
<class 'str'> <class 'str'> <class 'str'>

二、数字

1、整数 int

2、浮点数 float

 
 
a=12
b=85.3645
c=round(35.22254,1)

print(a,b,c)
print(type(a),type(b),type(c))
-------------------------------

12 85.3645 35.2
<class 'int'> <class 'float'> <class 'float'>

三、布尔值

a=False
b=True

print(a,b)
print(type(a),type(b))
-------------------------------

False True
<class 'bool'> <class 'bool'>

四、类型转换

a='1554'
b=98
c=2.33

print(a,b,c)
print(type(a),type(b),type(c))


a=int(a)
b=float(b)
c=str(c)

print(a,b,c)
print(type(a),type(b),type(c))
-------------------------------

1554 98 2.33
<class 'str'> <class 'int'> <class 'float'>
1554 98.0 2.33
<class 'int'> <class 'float'> <class 'str'>

五、空值

a=None

print(a)
print(type(a))
-------------------------------

None
<class 'NoneType'>

猜你喜欢

转载自www.cnblogs.com/cooper-wang/p/10266899.html
今日推荐