python学习之认识字符串

时间:2023-03-09 02:46:28
python学习之认识字符串

1.打印字符串

>>> print ("hello world")
hello world

2.使用“/"进行符号转义

>>> print ("hello"world")
File "<stdin>", line 1
print ("hello"world")
^
SyntaxError: invalid syntax
加“\”符号进行转义
>>> print ("hello\"world")

3.通过“+”号将字符串连接起来

>>> print ("hello"+" "+"world")
hello world

4.字符串还可以使用乘号

>>> print ("hello"*3)
hellohellohello

5.字符串变量

name="Jasper"
print("我的名字叫",name)
print("%s是我的名字"%name)
#变量在结尾直接用逗号隔开,变量在前面或者中间任意位置需要加字符串