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

歡迎訪問 生活随笔!

生活随笔

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

python

sqlserver 字符串中添加单引号_Python3 教程-- 7、字符串

發布時間:2025/3/19 python 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sqlserver 字符串中添加单引号_Python3 教程-- 7、字符串 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Python 字符串

除了數字,Python也能操作字符串。字符串有幾種表達方式,可以使用單引號或雙引號括起來:

>>> 'spam eggs''spam eggs'>>> 'doesn't'"doesn't">>> "doesn't""doesn't">>> '"Yes," he said.''"Yes," he said.'>>> ""Yes," he said."'"Yes," he said.'>>> '"Isn't," she said.''"Isn't," she said.'

Python中使用反斜杠轉義引號和其它特殊字符來準確地表示。

如果字符串包含有單引號但不含雙引號,則字符串會用雙引號括起來,否則用單引號括起來。對于這樣的輸入字符串,print() 函數會產生更易讀的輸出。

跨行的字面字符串可用以下幾種方法表示。使用續行符,即在每行最后一個字符后使用反斜線來說明下一行是上一行邏輯上的延續:

以下使用 來添加新行:

>>> '"Isn't," she said.''"Isn't," she said.'>>> print('"Isn't," she said.')"Isn't," she said.>>> s = 'First line.Second line.' # 意味著新行>>> s # 不使用 print(), 包含在輸出中'First line.Second line.'>>> print(s) # 使用 print(), 輸出一個新行First line.Second line.

以下使用 反斜線() 來續行:

hello = "This is a rather long string containingseveral lines of text just as you would do in C. Note that whitespace at the beginning of the line is significant."print(hello)

注意,其中的換行符仍然要使用 表示——反斜杠后的換行符被丟棄了。以上例子將如下輸出:

This is a rather long string containingseveral lines of text just as you would do in C. Note that whitespace at the beginning of the line is significant.

或者,字符串可以被 """ (三個雙引號)或者 ''' (三個單引號)括起來。使用三引號時,換行符不需要轉義,它們會包含在字符串中。以下的例子使用了一個轉義符,避免在最開始產生一個不需要的空行。

print("""甥慳敧: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to""")

其輸出如下:

Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to

如果我們使用"原始"字符串,那么 不會被轉換成換行,行末的的反斜杠,以及源碼中的換行符,都將作為數據包含在字符串內。例如:

hello = r"This is a rather long string containingseveral lines of text much as you would do in C."print(hello)

將會輸出:

This is a rather long string containingseveral lines of text much as you would do in C.

字符串可以使用 + 運算符串連接在一起,或者用 * 運算符重復:

>>> word = 'Help' + 'A'>>> word'HelpA'>>> ''''

兩個緊鄰的字面字符串將自動被串連;上例的第一行也可以寫成 word = 'Help' 'A' ;這樣的操作只在兩個字面值間有效,不能隨意用于字符串表達式中:

>>> 'str' 'ing' # >> 'str'.strip() + 'ing' # >> 'str'.strip() 'ing' #

總結

以上是生活随笔為你收集整理的sqlserver 字符串中添加单引号_Python3 教程-- 7、字符串的全部內容,希望文章能夠幫你解決所遇到的問題。

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