標籤:指定 div 技術 print 解決 images ret amp bsp
1、解決使用者輸入空行的辦法使用startwith判斷或者len(strs)>0
2、字串運用方法中strip和replace特別有用。
Python strip() 方法用於移除字串頭尾指定的字元(預設為空白格)。文法:
str.strip([chars]);
#!/usr/bin/pythonstr = "0000000this is string example....wow!!!0000000";print str.strip( ‘0‘ );#輸出結果為this is string example....wow!!!
只移除字串頭尾指定的字元,中間部分不會移除:
#!/usr/bin/python
str = "0000000this is string 0000example....wow!!!0000000";print str.strip( ‘0‘ );結果為:this is string 0000example....wow!!!
Python replace() 方法把字串中的 old(舊字串) 替換成 new(新字串),如果指定第三個參數max,則替換不超過 max 次。文法:
str.replace(old, new[, max])
#!/usr/bin/pythonstr = "this is string example....wow!!! this is really string";print str.replace("is", "was");print str.replace("is", "was", 3);結果為:thwas was string example....wow!!! thwas was really stringthwas was string example....wow!!! thwas is really string#old -- 將被替換的子字串。#new -- 新字串,用於替換old子字串。#max -- 可選字串, 替換不超過 max 次
3、
python的學習3