字符串用‘’或“”包裹起来。
>>> print('我是字符串')
我是字符串
>>> name='xiaoli'
>>> print(type(name))
<class 'str'>
type() 函数是python中的一个内置函数,主要用于获取变量类型,str表示是字符串类型。
字符串连接:
>>> name='xiaoli'
>>> print('hi',name)
hi xiaoli
>>> print('hi'+name)
hixiaoli
用+连接字符串时,可以加入空格分隔
>>> print('hi'+' '+name)
hi xiaoli
>>> print('hi'+' '+'xiaoli')
hi xiaoli
用*号也可以实现字符串相连,如下连续打印3次hello
>>> print('hello'*3)
hellohellohello