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函數

發佈了128 篇原創文章 · 獲贊 128 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章