国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 乌拉特中旗| 万山特区| 宣汉县| 洱源县| 霸州市| 凤山县| 汉源县| 滨州市| 新昌县| 阿荣旗| 陇南市| 定结县| 洪雅县| 都兰县| 滁州市| 马尔康县| 安达市| 南漳县| 温宿县| 博客| 东港市| 章丘市| 湘阴县| 子洲县| 罗甸县| 通许县| 甘南县| 永城市| 包头市| 明水县| 安义县| 科尔| 浦县| 浪卡子县| 精河县| 天气| 桃园市| 库尔勒市| 永昌县| 桑日县| 安达市|