標籤:恢複 一個 for pre ring monk ace python 使用者
-*-紙上得來終覺淺,絕知此事要恭行。-*-
# -*- coding:utf-8 -*-
# Author:sweeping-monk
name = "什麼是字串?"
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_1
print(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 darwin
Type "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)
python基礎實踐(一)