Python基础:数据类型、应用及转换

数据类型

字符串

由一个个字符串起来的组合,字符可以是一个数字、一个字母、一个文字,甚至是一个符号。字符串可以表达现实世界里的词、语句、表达式等

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员阿卢

谢谢鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值