class_3:数据类型/交互模式/ input输入

获取字符串长度

python 复制代码
#获取字符串长度
s = "hello world!"
print(len(s))
print(len("hello"))
#根据索引取字符
print(s[0])
print(s[11])
#type
a = 10
b = True
c = 1.0
d = None #空值类型
print(type(a))
print(type(b))
print(type(c))
print(type(d))

命令行模式:写好代码直接运行

交互模式:一行一行解析并返回结果

input:会统一将变量转换为字符串

python 复制代码
#BMI = 体重 /(身高 **2)
weight = float(input("请输入您的体重:单位是kg "))
height = float(input("请输入您的身高:单位是m "))
BMI = weight / (height ** 2)64
print("您的BMI为:" + str(BMI))
相关推荐
用户83562907805113 小时前
Python 实现 PowerPoint 形状动画设置
后端·python
ponponon14 小时前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python
Flittly14 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(5)Skills (技能加载)
python·agent
敏编程15 小时前
一天一个Python库:pyarrow - 大规模数据处理的利器
python
Flittly16 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(4)Subagents (子智能体)
python·agent
明月_清风1 天前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风1 天前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
ZhengEnCi2 天前
08c. 检索算法与策略-混合检索
后端·python·算法
明月_清风2 天前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python
明月_清风2 天前
Python 消失的内存:为什么 list=[] 是新手最容易踩的“毒苹果”?
后端·python