字符串是数组 像许多其他流行的编程语言一样,Python 中的字符串是表示 unicode 字符的字节数组。 但是,Python 没有字符数据类型,单个字符就是长度为 1 的字符串。
python 中的字符串字面量由单引号或双引号括起。
就像:
‘hello’ 等同于 “hello”。
可以使用 print() 函数显示字符串字面量:
实例
print(“Hello”)
print(‘Hello’)
运行实例
用字符串向变量赋值
通过使用变量名称后跟等号和字符串,可以把字符串赋值给变量:
实例
a = “Hello”
print(a)
运行实例
多行字符串
您可以使用三个引号将多行字符串赋值给变量:
实例
可以使用三个双引号:
a = “”“Python is a widely used general-purpose, high level programming language.
It was initially designed by Guido van Rossum in 1991
and developed by Python Software Foundation.
It was mainly developed for emphasis on code readability,
and its syntax allows programmers to express concepts in fewer lines of code.”""
print(a)
运行实例
或三个单引号:
实例
a = ‘’‘Python is a widely used general-purpose, high level prog