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))
相关推荐
金銀銅鐵13 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf14 小时前
Agent 流程编排
后端·python·agent
copyer_xyf14 小时前
Agent RAG
后端·python·agent
copyer_xyf14 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf15 小时前
Agent 记忆管理
后端·python·agent
星云穿梭1 天前
用Python写一个带图形界面的学生管理系统——完整教程
python
金銀銅鐵1 天前
用 Pygame 实现 15 puzzle
python·数学·游戏
黄忠1 天前
大模型之LangGraph技术体系
python·llm
hboot2 天前
AI工程师第二课 - 数据处理
人工智能·python·数据分析
用户8356290780512 天前
使用 Python 自动化 PowerPoint 形状布局与格式设置
后端·python