字符串可以通過以下幾種方式進行賦值:
s = "Hello, world!"
s1 = "Hello"
s2 = "world!"
s = s1 + ", " + s2
s1 = "Hello"
s = s1 * 3 # 將字符串"Hello"重復3次
name = "Alice"
age = 25
s = "My name is {} and I am {} years old.".format(name, age)
name = "Alice"
age = 25
s = f"My name is {name} and I am {age} years old."
無論使用哪種方式,都可以通過賦值運算符將字符串賦值給變量。