math函数
import math
a = math.sin(1)
print(a)
求根公式
a = 1
b = 9
c = 20
x1 = (-b + (b ** 2 - 4 * a * c) ** (1/2)) / (2 * a)
x2 = (-b - math.sqrt(b ** 2 - 4 * a * c)) / (2 * a)
print(x1)
print(x2)
字符串连接
callme = "Yo,what\'s up,"
print(callme + "Janne")
print(callme + "Danny")
对字符串求长度
s = "hello world"
print(len(s))
通过索引获取单个字符
print(s[0])
布尔类型
b1 = True
b2 = False
空类型
n = None
type函数
print(type(s))
print(type(b1))
print(type(n))
print(type(10))
print(type(10.5))
user_age = input("请输入您的年龄:")
print(user_age)
强制类型转换
user_age_after = int(user_age)+100
print(user_age_after)
print("您100年之后" + str(user_age_after) + "岁" )
print("您100年之后" + str(int(user_age)+100) + "岁" )
条件判断语句
emotion = int(input("你的心情指数:"))
if emotion >= 60:
print("嘻嘻嘻")
else:
print("呜呜呜")
嵌套语句
if emotion <= 60:
if emotion == 0:
print("回家吧孩子,回家吧")
else:
print("那真是太糟糕了")
else:
print("这很好了")
多个条件判断
if 0 <= emotion < 30:
print("孩子你还好吗")
elif 30 <= emotion < 60:
print("这很坏了")
elif 60<= emotion < 100:
print("啦啦啦")
elif emotion >=100:
print("好心情指数爆表!!!!!!!!")
else:
print("输入错误!!!")
与或非
print("and-&&")
print("or-||")
print("not--")
列表
shop_list = ["商品1","商品0","商品3"]
print(shop_list)
shop_list.append("商品4")
print(shop_list)
shop_list.remove("商品3")
print(shop_list)
print(shop_list[0])
print(max(shop_list))
print(min(shop_list))
print(sorted(shop_list))
print(len(shop_list))
字典
contacts = {
("小明",20):"18700000000",
("小红",19):"15000000000"
}
contacts[("小兰",18)] = "19000000000"
a = ("小明",20) in contacts
print(contacts)
del contacts[("小明",20)]
print(contacts)
print(contacts[("小红",19)])
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?