日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 字符串前加r和f

發布時間:2025/3/19 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 字符串前加r和f 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

字符串前加 f 的含義

    • 看例子
    • 用法
    • 總結

?

官方文檔:點擊這里
如果你今天將就而選擇參考了我的文檔,總有一天你還是會去閱讀官方文檔。

先看例子

list_ = [1,2,3] print(list_, f'has a length of {len(list_)}.')# [1,2,3] has a length of 3.
  • 1
  • 2
  • 3
  • 4

看懂這個例子,用法也基本掌握了。

用法

官方文檔:

Format strings contain “replacement fields” surrounded by curly braces {}. Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}.

大概意思就是:

格式化 {} 內容,不在 {} 內的照常展示輸出,如果你想輸出 {},那就用雙層 {{}} 將想輸出的內容包起來。

效果如下:

list_ = [1,2,3] print(list_, f'has a length of {len(list_)}.') # [1,2,3] has a length of 3.print(list_, f'has a length of {{len(list_)}}.') # [1,2,3] has a length of {len(list_)}.print(list_, f'has a length of {{{len(list_)}}}.') # [1,2,3] has a length of {3}.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

總結

f-string:?formatted string literals, 格式化字符串常量。

功能同str.format() %-formatting,
較兩者更簡潔易用,推薦使用
需要注意的是,Python3.6及以后的版本可用

?

?

字符串前加 r?的含義

print (glob.glob(r"/home/qiaoyunhao/*/*.png"),"\n")#加上r讓字符串不轉義

總結

以上是生活随笔為你收集整理的python 字符串前加r和f的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。