占位符


  • 占位符
  1. %s : 字符串
  2. %d : 整數
  3. %f : 浮點數
name = "渣渣輝"
age = 50

# s = "你好,渣渣輝,年齡50,在貪玩藍月等你來砍我"
# %s:字符串
# %d:整數
#s = "你好,%s,年齡%d,在貪玩藍月等你來砍我" %(name,age)
#s = "你好,,年渣渣輝,齡%f,在貪f玩藍月等你來砍我" % age
s = "你好,,年渣渣輝,齡%.2f,在貪f玩藍月等你來砍我" % age
  • .format
# .format
# s = "你好,{},年齡{},在貪f玩藍月等你來砍我" .format(name, age)
s = "你好,{n},年齡{a},在貪f玩藍月等你來砍我" .format(n=name,a=age)
  • f-string
# f-string
s = f"你好,{name},年齡{age},在貪f玩藍月等你來砍我"

print(s)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM