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

首頁 > 編程 > Python > 正文

python實現剪切功能

2020-02-16 00:50:55
字體:
來源:轉載
供稿:網友

本文實例為大家分享了python實現剪切功能的具體代碼,供大家參考,具體內容如下

#!/usr/bin/env python#coding: utf8import sysmystr = []def inputstr(): item = raw_input('Please input your string:') mystr[:] = [] #清空列表 mystr.extend(item) #將輸入的字符串拆開為一個一個字符填入列表def printstr(): lenth = len(mystr) - 1 index = 0 print "Your result is :" print "*****" + ''.join(mystr) + "*****" #.join()與之前的extend對應,將字符合并為一個元素,用''里面的內容分割。''里面為空,則字符之間沒有間隙 print "----------------分割符----------------"def leftstrip(): #左剪切 while True: if mystr[0] == ' ':  mystr.pop(0) else:  break printstr()def rightstrip():#右剪切 while True: if mystr[-1] == ' ':  mystr.pop() else:  break printstr()def bothsidestrip(): while True: if mystr[-1] == ' ':  mystr.pop() elif mystr[0] == ' ':  mystr.pop(0) else:  break printstr()#使用字典的方式,實現case的語法功能CMDs = {'l':leftstrip,'r':rightstrip,'b':bothsidestrip}def showmenu(): prompt = """(L)eftstrip(R)ightstrip(B)othsidestrip(Q)uitPlease select a choice:""" while True: choice = raw_input(prompt).lower() if choice not in 'lrbq':  continue if choice == 'q':  break inputstr() CMDs[choice]()if __name__=='__main__': showmenu()

效果圖:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桐柏县| 盐边县| 进贤县| 甘孜| 琼结县| 普宁市| 库伦旗| 定安县| 白山市| 泰和县| 福建省| 茌平县| 南澳县| 兴文县| 长宁县| 闻喜县| 台南县| 右玉县| 桓仁| 遵义县| 临颍县| 丰都县| 泉州市| 罗城| 漳浦县| 宾阳县| 遵义县| 通许县| 宜兴市| 普宁市| 东海县| 达孜县| 武强县| 鞍山市| 科技| 辰溪县| 酉阳| 饶阳县| 中西区| 永济市| 榆林市|