看板 Python 關於我們 聯絡資訊
請問一個簡單的問題 debug時每次想要同時印出 數字跟字串 就會顯示錯誤 說不能同時印字串跟數字 雖然後來改用 str.format的方法"{1} {2} {3}".foramt....... 解決了 但是覺得這個方法太慢了 請問要印出字串跟數字的簡單方法是? 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.166.173.78 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1530763272.A.5E0.html
IAMPF: print string + str(int) 07/05 12:07
ironmanstock: 發現用逗號也行 print str,數字,可是好像會多出空格 07/05 12:16
coeric: 逗號會有一格空格 07/05 13:12
bckkt: n = 5 07/05 13:32
bckkt: print("%d"%n) 07/05 13:33
bckkt: str1 = "呵呵" 07/05 13:33
bckkt: print("%s%d"%(str1,n)) 07/05 13:34
ironmanstock: 對,這也是一種方法~~ 07/05 18:11