Guibs 的 Python學習_字串

來源:互聯網
上載者:User
Guibs 的 Python學習_字串

# 字串# Python 中, 用引號括起來的都是字串. 引號可以是單引號, 也可以是雙引號"This is a string"'This is also a string'# 因而可以在字串中包含 " 或 ''I told myself, "you are Gubis"'"The name 'Guibs' is my nickname"# 首字母大寫指定字串# [.title()]name = 'Macbook pro'print(name.title())# 全部大寫指定字串# [.upper()]print(name.upper())# 全部小寫字串# [.lower()]print(name.lower())# 合并(拼接)字串# [使用 + 拼接字串]first_name = "guibs"last_name = 'g'full_name = first_name + " " + last_nameprint(full_name)hello_message = "Hello, " + full_name.title() + "!"print(hello_message)# 定位字元# [\t]print("Python")print("\tPython")# 分行符號# [\n]print("123")print("1\n2\n3")# 刪除字串空白# [.rstrip() 刪除字串末尾多餘空白]print("刪除字串 Swift and Python 末尾多餘空白")favorite_language = " Swift and Python "print(favorite_language + " are my favorite languages")print(favorite_language.rstrip() + " are my favorite languages" + "\n")# [.lstrip() 刪除字串開頭多餘空白]print("刪除字串 Swift and Python 開頭多餘空白")print(favorite_language + " are my favorite languages")print(favorite_language.lstrip() + " are my favorite languages" + "\n")# [.strip() 刪除字串頭尾多餘空白]print("刪除字串 Swift and Python 頭尾多餘空白")print(favorite_language + " are my favorite languages")print(favorite_language.strip() + " are my favorite languages" + "\n")# 正確使用引號# 保留 "" 顯示print('I told myself, "you are Gubis"')# 保留 '' 顯示print("The name 'Guibs' is my nickname")

以上就是Guibs 的 Python學習_字串的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.