CS61A python---字符串/常见错误/*args

CS61A python---字符串

str(1) = '1'

把数字等转化为字符串

 

+ : 连接字符串

print(f"Debuting at #{place}: '{song}' by {artist}")

复制代码
artist = "Lil Nas X"
song = "Industry Baby"
place = 2

print("Debuting at #" + str(place) + ": '" + song + "' by " + artist)
print(f"Debuting at #{place}: '{song}' by {artist}")

# Debuting at #2: 'Industry Baby' by Lil Nas X
# Debuting at #2: 'Industry Baby' by Lil Nas X

greeting = 'Ahoy'
noun = 'Boat'

print(f"{greeting.lower()}, {noun.upper()}yMc{noun}Face")
print(f"{greeting*3}, {noun[0:3]}yMc{noun[-1]}Face")
# ahoy, BOATyMcBoatFace
# AhoyAhoyAhoy, BoayMctFace
复制代码

 

 

各种报错

 

NoneType

函数没有返回值

NameError

找不到名称(未定义)

UnboundLocalError

 

*args

*args 支持调用时给各种数量不同的参数,比如max()函数

 

posted @   liankewei123456  阅读(44)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2020-02-26 dtoj3317. 人类基因(human)
2020-02-26 dtoj2623. B
点击右上角即可分享
微信分享提示