1.字符串的书写
str='stensmd'
str="stensmd"
str='''stensmd'''
str="""stensmd"""
2.四种书写的区别
若都在其中插入回车
s='hello ' \
'everyon'
print(s)
print(type(s))
a="hello " \
"world"
print(a)
print(type(a))
str='''ite
amt'''
print(str)
print(type(str))
ss="""hello
world"""
print(ss)
print(type(ss))
运行结果为
hello everyon
<class 'str'>
hello world
<class 'str'>
ite
amt
<class 'str'>
hello
world
<class 'str'>
可见三引号符支持回车换行,并且不会添加任何字符
3.对于字符串类似I’m ok,含有单引号,此时不可以再用单引号读写,正确形式如下
sss="I'am ok"
(或)
sss='I\'m ok'
4.字符串输出
passage='zxcvbnm'
print('%s' %passage)
print(f'{passage}')
5.输入字符串
ssss=input('输入:')