-*-紙上得來終覺淺,絕知此事要恭行。-*-# -*- coding:utf-8 -*-# Author:sweeping-monkname = "什麼是字符串?"What_is_a_string = "字符串就是一系列字符,在python中,用引號括起來的都是字符串,其中引號能夠是單引號,也能夠是雙引號。"print(name)print(What_is_a_string)Question_1 = "使用什麼方法修改字符串的大小寫?"Method_1 = "程序結果以下:"print(Question_1)print(Method_1)name_one = "ada lovelace"print(name_one.title()) #.title()不加任何參數能夠把第一個字母變成大寫。方法是python可對數據執行的操做。print(name_one.lower()) #這個方法能夠將字符串轉換成小寫,在存儲數據時頗有用。Question_2 = "合併和拼接字符串"Method_2_1 = "程序結果以下:"print(Question_2)print(Method_2_1)Last_name = "liu"name_1 = "xiaole"full_name = Last_name + name_1print(full_name)full_name = Last_name + " " + name_1 #引號內是空格print(full_name)full_name = Last_name + "_" + name_1 #引號內是下劃線_,下面就不在贅述。print(full_name)message = "hell wolrd," + full_name + " ! "print(message)Question_3 = "如何使用製表符和換行符來添加空白?"conception = "在編程中,空白泛指任何非打印字符,如空格,製表符,換行符。"Method_3_1 = "程序結果以下:"print(Question_3)print(conception)print(Method_3_1)print("編程語言:" "python")print("編程語言:" "\npython") #換行用換行符\n.print("編程語言:" "\n\tpython") #另外一行開頭空兩格,用製表符\t.print("編程語言:" "\n\tpython\n\tC++\n\tjava") #配合使用。Question_4 = "如何刪除空白?"conception_4_1 = "空白很重要,由於在實際工做中咱們常常要比較兩個字符串是否同樣,例如登錄網站時,檢查用戶名"Method_4_1 = "程序請在cmd終端python3下執行:"print(Question_4)print(conception_4_1)print(Method_4_1)cmd_D = '''xiaolefdeMacBook-Air:ji_chu xiaole$ python3 #請在cmd命令行下操做才能看到結果。Python 3.6.3 (v3.6.3:2c5fed86e0, Oct 3 2017, 00:32:08)[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> name = 'python '>>> name'python '>>> name.rstrip()'python' #只是臨時把空白給刪除了。>>> name'python ' #再執行空白又恢復了。>>> name = name.rstrip() #永久刪除空白的方法是把刪除的結果:'python'存回到原來的變量中,這是通用方法。>>> name'python'>>> name_1 = ' python '>>> name_1.rstrip() #刪除後面空白的方法' python'>>> name_1.lstrip() #刪除前面空白的方法'python '>>> name_1.strip() #一塊兒刪除先後的方法。'python''''print(cmd_D)