数据类型
字符串
由一个个字符串起来的组合,字符可以是一个数字、一个字母、一个文字,甚至是一个符号。字符串可以表达现实世界里的词、语句、表达式等
Chinese = '镜像世界'
English = "mirror world"
print(Chinese)
print(English)
整数
不带小数点的数字
a = 10
b = -60
c = 6841
d = 0
浮点数
1.0
3.14159
-0.33
数据应用
四则运算
四则运算口诀:从左到右顺序来,括号里面优先算,乘除排在加减前
t(499*561+10620-365)
print((5025-525)/100+18*17)
字符串拼接
hero = '我'
organization = 'python编程'
identity = '爱好者'
action = '是'
ID = '007'
print(hero+action+organization+identity+ID)
print(organization+identity+ID+action+hero)
输出结果
我是python编程爱好者007
python编程爱好者007是我
数据累形成查询——type函数
who = '我的'
action = '是'
destination = '镜像世界'
number = 153
code = '通行密码'
type(who)
type(action)
type(destination)
type(number)
type(code)
运行结果
<class ‘str’>
<class ‘str’>
<class ‘str’>
<class ‘int’>
<class ‘str’>
数据转换
str()函数
who = '我的'
action = '是'
destination = '镜像世界'
number = 153
code = '通行密码'
print(who+destination+code+action+str(number))
运行结果是:我的镜像世界通行密码是153
int()函数
number1 = '6'
number2 = '1'
print(int(number1)+int(number2))
运行结果是:7
float()函数
height = 188.0
weight = 180.0
age = '89'
print(float(height))
print(float(weight))
print(float(age))
运行结果是:
188.0
180.0
89.0