原创 python中定義,訪問,修改列表的值

python中列表的定義 # 定義列表,要定義元組就有()表示 num = [10,11,12,13] name = ["aa","bb","cc","dd","ee"] print(num) print(name) #

原创 python添加和刪除列表中的元素

添加和刪除列表中的元素 添加列表中的元素 num = [10,11,12,13] # num list name = ["aa","bb","cc","dd","ee"] num.append(14) # 在末尾加數字 nam

原创 python列表轉成字符串,同時自定義分隔符

python列表轉成字符串,同時自定義分隔符 # 定義分隔符 a = ',' mylist = ['Brazil', 'Russia', 'India', 'China'] print(a.join(mylist)) 輸出:

原创 Python判斷字符串的開頭字符

Python判斷字符串的開頭字符 str = 'lewis test' # 是該字符串開頭的,返回true。反之,返回:false print str.startswith('lew') print str.startswith

原创 Python字符串中增加變量--%方式(格式化輸出)

Python字符串中增加變量–%方式(格式化輸出) value = 10 string = 'test' # 格式化輸出int和str int_value = 'lewis is %d' % value str_value =

原创 Python處理字符串中的空白

Python處理字符串中的空白 str = ' lewis liu ' # 刪除字符串中右邊的空白 print(str.rstrip()) # 刪除字符串中左邊的空白 print(str.lstrip()) # 刪除字

原创 Python字符串大小寫處理

Python字符串大小寫處理 str = 'Hello world' # 首字母大寫 print(str.title()) # 全部大寫 print(str.upper()) # 全部小寫 print(str.lower())

原创 Python定義多行字符串

Python定義多行字符串可以用符號"""來表示 Python定義多行字符串可以用符號"""來表示 str ="""abc defg hijk lmno """ print(str) 提供Python自動化腳本編寫服務,如有需

原创 Python字符串中增加變量--f強制法

Python字符串中增加變量–f強制法 value = 10 string = 'years old' # 字符串前面增加f,然後強帶變量 value = f'lewis {value} {string}' print(val

原创 Python字符串轉列表

Python字符串轉列表 要轉列表這個字符首先要有一定的規律,比如有空格,逗號,\n,\t等 str = 'SYN,FIN,RESET,ACK' print(str.split(',')) 輸出結果: ['SYN', 'FIN'

原创 Python字符串中增加變量--format方法

Python字符串中增加變量–format方法 value = 10 string = 'test' # {0}:表示第一個變量 # {1}:表示第二個變量 # 一次類推 value = 'lewis {0} {1}'.form

原创 Python輸出原始字符串

Python輸出原始字符串 value1字符串會換行 value1 = 'abc\nabc' # value2輸出原始字符串不會換行 value2 = r'abc\nabc' # 輸出原始字符串不會換行 print(valu

原创 Python在字符串中增加換行和縮進

Python在字符串中增加換行和縮進 可以用製表符 \n 和縮進符 \t 來表述 str1 = 'lewis\n' str2 = '\tlewis' print(str1) print(str2) 提供Python自動化腳本編

原创 Python搜索字符串中的關鍵字

Python搜索字符串 簡單解釋一下我寫的這三個函數: after_keywords_last:從後往前開始查找字符串中的關鍵字,然後返回這個關鍵字後面所有的內容,包括關鍵字本身。注意查到了就不會再繼續找。 after_keywo

原创 Python字符串索引取值

Python字符串索引取值 str1 = 'Hello World' print(str1[0]) print(str1[0:5]) print(str1[6:11]) 輸出結果: H Hello World 提供Pytho