2018 01 08 字串處理函式

2021-08-14 11:02:29 字數 1683 閱讀 3816

str.capitalize()返回乙個字串,首字母大寫

str.replace()替代字元

str.split()將字串切分,返回乙個列表,列表的元素是字元,預設用空格切分(把字串切成列表)

str.join()引數是個可迭代的物件,返回的是乙個字串。

string 模組

string.capitalize()

string.replace('hello','o','o')

string 

# from string import capitalize

## help(capitalize

s='hello'

prints.capitalize()

prints

# help (s.replace)

s='hello,h'

prints.replace('h'

,'h')

prints.replace('h'

,'h',1)

# help(str.replace)

prints.split()

s='hello a\tb

\nc'

prints.split()

s1='abc'

prints1.split()

prints.split(' ')

ip='192.168.1.1'

printip.split()

printip.split('.')

printip.split('.',1)

printrange (10)

print''.join([str(i)foriinrange(10)])

hello

hello

hello,h

hello,h

['hello,h']

['hello', 'a', 'b', 'c']

['abc']

['hello', 'a\tb\nc']

['192.168.1.1']

['192', '168', '1', '1']

['192', '168.1.1']

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

printrange (10)

print''.join([str(i)foriinrange(10)])

printint (''.join([str(i)foriinrange(10)]))

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

0123456789

123456789

05 2 字串處理函式

字串分割函式 strsplit strsplit x,split,extended true,fixed false,perl false strsplit 123abcderabggg ab 按照ab分割字串 字串連線 計算字串的字元數 nachr 字串擷取 substr x,start,stop...

專案30 1字串處理函式

任務和 字串的處理函式 字串str1和str2連線,連線後的結果存放到str1中 檔名 main.c 完成日期 2016.7.10 問題描述 字串的處理函式 字串str1和str2連線,連線後的結果存放到str1中 程式輸出 include include char astrcat char str...

8 8字串處理

字串處理 string 無子類 hello 構造字串物件 public int length 獲取字串的長度 system.out.println 輸入姓名 scanner sc new scanner system.in string str sc.nextline string str 李芳 s...