我需要列印以下代碼:
print('hello "my friend '{}' "'.format(name))
這樣輸出是:
'hello "my friend 'ABCD' " '
但我得到了錯誤:End of Statement expected
什么是正確的語法?
uj5u.com熱心網友回復:
如果要在字串中使用引號,則需要轉義引號:
print('hello "my friend \'{}\'"'.format(name))
uj5u.com熱心網友回復:
試試這個,
print("""hello "my friend '{}' " """.format(name))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/465642.html
標籤:Python python-3.x
