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()函数

相关