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

歡迎訪問 生活随笔!

生活随笔

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

python

python字符串转义序列_Python | 忽略字符串中的转义序列

發布時間:2025/3/11 python 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python字符串转义序列_Python | 忽略字符串中的转义序列 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

python字符串轉義序列

First see, how escape sequence works?

首先看,轉義序列如何工作?

In the below example, we are using some of the escape sequence and their outputs, we are printing single quote (\'), double quotes (\"), printing path (double slash) (\\) and using hexadecimal values (\x).

在下面的示例中,我們使用一些轉義序列及其輸出,我們將打印單引號( \' ),雙引號( \“ ),打印路徑(雙斜杠)( \\ )并使用十六進制值( \ x )。

Program:

程序:

#printing single quote str1 = "Hi, I\'m IncludeHelp" #printing double quotes str2 = "\"Hello world\"" #printing path str3 = "D:\\work_folder\\python_works" #using hexadecimal values str4 = "This is \x49\x6E\x63\x6C\x75\x64\x65\x48\x65\x6C\x70"print(str1); print(str2); print(str3); print(str4);

Output

輸出量

Hi, I'm IncludeHelp "Hello world" D:\work_folder\python_works This is IncludeHelp

忽略轉義序列 (Ignoring Escape Sequences)

To ignoring escape sequences in the string, we make the string as "raw string" by placing "r" before the string. "raw string" prints as it assigned to the string.

為了忽略字符串中的轉義序列 ,我們通過在字符串前面放置“ r” ,使字符串成為“原始字符串” 。 “原始字符串”將按分配給該字符串的方式打印。

Program:

程序:

#ignoring escape sequences#ignoring single quote escape sequences str1 = r"Hi, I\'m IncludeHelp" #ignoring double quotes escape sequences str2 = r"\"Hello world\"" #ignoring path escape sequences str3 = r"D:\\work_folder\\python_works" #ignoring hexadecimal values escape sequences str4 = r"This is \x49\x6E\x63\x6C\x75\x64\x65\x48\x65\x6C\x70"print(str1); print(str2); print(str3); print(str4);

Output

輸出量

Hi, I\'m IncludeHelp \"Hello world\" D:\\work_folder\\python_works This is \x49\x6E\x63\x6C\x75\x64\x65\x48\x65\x6C\x70

Other python string programs...

其他python字符串程序...

  • Python | Declare, assign and print the string (Different ways).

    Python | 聲明,分配和打印字符串(不同方式)。

  • Python | Access and print characters from the string.

    Python | 訪問和打印字符串中的字符。

  • Python | Program to print words with their length of a string.

    Python | 程序打印帶有字符串長度的單詞。

  • Python | Print EVEN length words.

    Python | 打印偶數個長度的單詞。

  • Python | Count vowels in a string.

    Python | 計算字符串中的元音。

  • Python | Passing string value to the function.

    Python | 將字符串值傳遞給函數。

  • Python | Create multiple copies of a string by using multiplication operator.

    Python | 使用乘法運算符創建一個字符串的多個副本。

  • Python | Appending text at the end of the string using += Operator.

    Python | 使用+ =運算符在字符串末尾附加文本。

  • Python | Concatenate two strings and assign in another string by using + operator.

    Python | 連接兩個字符串,并使用+運算符分配另一個字符串。

  • Python | Check if a substring presents in a string using 'in' operator

    Python | 使用'in'運算符檢查字符串中是否存在子字符串

翻譯自: https://www.includehelp.com/python/ignoring-escape-sequences-in-the-string.aspx

python字符串轉義序列

總結

以上是生活随笔為你收集整理的python字符串转义序列_Python | 忽略字符串中的转义序列的全部內容,希望文章能夠幫你解決所遇到的問題。

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