9 - python 字符串操作

1. 如何同时在字符串中显示单引号和双引号

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

# 转义符
print('"hello" \'world\'')
hello "world"
hello 'world'
"hello" 'world'

2. 让字符串中的转义符失效有几种方法(r、repr和\)

print(r'Let \'s go!')
Let \'s go!
print('hello \nworld')
print(repr('hello \nworld'))
hello 
world
'hello \nworld'
print('hello \\nworld')
hello \nworld

3. 如何保留字符串的原始格式

print('''
    hello
            world
''')
    hello
            world


10 - python print函数

发布了107 篇原创文章 · 获赞 101 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_29339467/article/details/104163833