python字符串转义序列_Python | 忽略字符串中的转义序列
python字符串轉(zhuǎn)義序列
First see, how escape sequence works?
首先看,轉(zhuǎn)義序列如何工作?
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).
在下面的示例中,我們使用一些轉(zhuǎn)義序列及其輸出,我們將打印單引號( \' ),雙引號( \“ ),打印路徑(雙斜杠)( \\ )并使用十六進(jìn)制值( \ 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忽略轉(zhuǎn)義序列 (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.
為了忽略字符串中的轉(zhuǎn)義序列 ,我們通過在字符串前面放置“ 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\x70Other 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 | 打印偶數(shù)個長度的單詞。
Python | Count vowels in a string.
Python | 計算字符串中的元音。
Python | Passing string value to the function.
Python | 將字符串值傳遞給函數(shù)。
Python | Create multiple copies of a string by using multiplication operator.
Python | 使用乘法運算符創(chuàng)建一個字符串的多個副本。
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字符串轉(zhuǎn)義序列
總結(jié)
以上是生活随笔為你收集整理的python字符串转义序列_Python | 忽略字符串中的转义序列的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 春节抽空读了8本书,只有这本书我1字不落
- 下一篇: java程序员个人能力介绍_Java操作