format在python中是什么意思(python中的format什么意思)
生活随笔
收集整理的這篇文章主要介紹了
format在python中是什么意思(python中的format什么意思)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Python2.6 開始,新增了一種格式化字符串的函數 str.format(),它增強了字符串格式化的功能。
基本語法是通過 {} 和 : 來代替以前的 % 。
format函數可以接受不限個參數,位置可以不按順序。
實例
>>>"{} {}".format("hello", "world") # 不設置指定位置,按默認順序
'hello world'
>>> "{0} {1}".format("hello", "world") # 設置指定位置
'hello world'
>>> "{1} {0} {1}".format("hello", "world") # 設置指定位置
'world hello world'
登錄后復制
相關推薦:《Python教程》
以上就是format在python中是什么意思的詳細內容,更多請關注風君子博客其它相關文章!
總結
以上是生活随笔為你收集整理的format在python中是什么意思(python中的format什么意思)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Shady 深度学习课程
- 下一篇: 投影仪闪屏怎么办