如何在Python中使用雙引號?
雙引號用於表示字串或字元,也可以在print函式中用於列印定義的語句作為輸出。單引號和雙引號的功能相同。我們可以根據需要使用任何型別的引號。以下是使用Python程式語言用雙引號建立字串的語法。
str = “text”
其中:
“ ” 是雙引號
text 是要以字串格式顯示的資料
示例
讓我們來看一個例子,瞭解雙引號在Python中的功能和用法。首先,我們透過在雙引號中傳遞句子來建立一個字串,並將其賦值給變數str。接下來,我們透過呼叫字串變數名st來列印建立的字串。之後,我們使用type函式列印字串的型別。
str = "Double quotes in python programming" print(str) print(type(str))
輸出
Double quotes in python programming <class 'str'>
示例
當我們將句子用雙引號傳遞給print函式時,該句子將被列印。
print("Double quotes used in print statement")
輸出
以下是print語句中使用的雙引號的輸出。在輸出中,我們可以看到在雙引號中傳遞給print的語句。
Double quotes used in print statement
示例
讓我們來看另一個例子,瞭解雙引號在Python中的功能和用法。
在程式碼中,首先我們用單引號組合建立一個字串,透過在雙引號中傳遞句子並將其賦值給變數st。接下來,我們透過呼叫字串變數名st來列印建立的字串。之後,我們使用type函式列印字串的型別。
st = "Welcome to 'Python Tutorial' from TutorialsPoint" print(st) print(type(st))
輸出
Welcome to 'Python Tutorial' from TutorialsPoint <class 'str'>
示例
在這個例子中,我們將一段文字用雙引號括起來並賦值給變數。
st = " Example to understand the working, and functionality of the 'double quotations' in python programming language. The following code format can \n be used for using the double quotations." print(st)
輸出
Example to understand the working, and functionality of the 'double quotations' in python programming language. The following code format can be used for using the double quotations.
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP