Python

Python基础(2) - 字符串使用

2020-02-18  本文已影响0人  xianling_he

如何使用转义符

print("hello 'world'")
print('hello "world"')
print('"hello" \'world\' ')

如何让转义符失效

print(r'Let \'s talk!')
print(repr('Let \'s talk'))
print(repr('hello \n world'))
print('hello \\n world')

保持字符串的原始格式

print('''
please 
  talk 
    with 
      me
''')
print("""
please 
  talk 
    with 
      me
""")

总结:
1.使用转义符可以输出任何字符,包括双、单引号
2.通过三种方式(在字符串前加入r,repr 和 反斜杠())可以让转义符失效
3.用三对单引号或者双引号可以让字符串保留原始格式

he.xianling加油~

上一篇 下一篇

猜你喜欢

热点阅读