14天Python编程从入门到实践--Day3:数值类型

Python的标准数据类型非常简单就以下几种:
Python:标准数据类型:Number,String,List[],Tuple()元祖,Dict{}

#Number分为整数int和浮点float

x1 = 13
x2 = 13.0
print(x1,x2)
print(x1+x2)
print(type(x1),type(x2))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 13.0
26.0
 
#String字符串
x1 = 'hello'
x2 = 'world'

#多行字符串
x3 = '''a
b
c
'''
print(x1,x2)
print(x3)
print(type(x3))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hello world
a
b
c


#Bool布尔型
a = True 
b = False
print(a == 1)
print(b == 1)
print(b == 0)
3 > 2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
True
False
True
Out[5]:True
#列表:用[]标识的有序的对象,支持数字,字符串以及嵌套列表
lst1 = [1,3,4,6,7]
print(lst1)
lst2 = [1,4,5,'hello',lst1]
print(lst2)
print(lst2[4],type(lst2[4]))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(1, 4, 5, 6, 9) 
[100, 4, 5, 6, 9] 
#字典Dict:用{}标识
dict1 = {'a':100, 'b':'你那呢'}
print(dict1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{'a': 100, 'b': '你那呢'}
#数据类型转换方法 **int float str 三种  list/tuple/dict后面总结
var1 = 10
print(type(var1))
var2 = float(var1)
print(var2,type(var2))
var3 = str(var2)
print(var3,type(var3))
print(var2 + 1)
print(var3 + '1')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

10.0 
10.0 
11.0
10.01

你可能感兴趣的:(14天Python编程从入门到实践--Day3:数值类型)