国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

python核心編程第六章課后題自己做的答案

2019-11-14 17:05:49
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

6–6. 字符串.創(chuàng)建一個(gè) string.strip()的替代函數(shù):接受一個(gè)字符串,去掉它前面和后面的 空格(如果使用 string.*strip()函數(shù)那本練習(xí)就沒(méi)有意義了) 

 1 'Take a string and remove all leading and trailing whitespace' 2  3 def newStrip(str): 4     'delete blanks around a string' 5     _end = len(str) 6     _start = 0 7      8     # delete the blanks at the beginning of the string 9     for i in range(_end):10         if str[i] != ' ':11             _start = i12             break              13     else:14         PRint 'invalid: The string is a blank string.'     # if the string is a 15         _blank = True                                      # blank string16         17     18     # delete the blanks in the end of the string19     for i in range(-1, _start - _end, -1):20         if str[i] != ' ':21             _end = _end + i22             break      23     if not _blank:24         print '-' + str[_start: _end] + '-'   # print '-' make sure the function work25 26 # test27 if __name__ == '__main__':28     newStrip(raw_input('Enter a string: '))

 

6–7. 調(diào)試.看一下在例 6.5 中給出的代碼(buggy.py)

(a)研究這段代碼并

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 阿巴嘎旗| 赣州市| 宾阳县| 遂平县| 寿光市| 安达市| 无棣县| 紫云| 桐梓县| 安岳县| 绥芬河市| 永清县| 文安县| 临夏市| 托里县| 连平县| 剑阁县| 丽水市| 邳州市| 玉溪市| 永嘉县| 新竹县| 禹城市| 小金县| 林周县| 广西| 安庆市| 天水市| 阜平县| 成安县| 彝良县| 亳州市| 积石山| 七台河市| 阿坝| 曲阜市| 隆回县| 图木舒克市| 雷州市| 稻城县| 启东市|