如何在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("Double quotes used in print statement")
输出
下面是在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.