看到这个答案。
字符串是表示文本值的 Python 对象。它可以从字符串文字构建,也可以从文件中读取,也可以来自许多其他来源。
我真的不明白,如何从字符串文字构建字符串对象?
'''
multiline
content
'''
另外,上面的字符串文字如何?请帮我理解字符串文字和字符串对象之间的区别?
请参阅关于Literals的 python 文档:
文字是某些内置类型的常量值的符号。
字符串文字是存在于源代码中的东西——它是一种写入字符串值的方式。字符串对象是对象在内存中的表示str
。您可以将其与整数文字进行比较,例如5
:
x = 5 # x is assigned an integer value, using the literal `5`
y = x + x # x is assigned a value
# Both are `int` objects
print(isinstance(x, int)) # True
print(isinstance(x, int)) # True
foo = "hello" # foo is assigned a str value, using the literal `"hello"`
bar = foo.upper() # bar is assigned a `str` value
# Both are `str` objects
print(isinstance(foo, str)) # True
print(isinstance(bar, str)) # True
如果需要,您可以进一步阅读:
在计算机科学中,文字是表示源代码中固定值的符号。... 文字通常用于初始化变量,...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句