python實現(xiàn)剪切功能
更新時間:2019年01月23日 10:44:07 作者:huangyingleo
這篇文章主要為大家詳細介紹了一段python代碼編寫實現(xiàn)的剪切功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了python實現(xiàn)剪切功能的具體代碼,供大家參考,具體內(nèi)容如下
#!/usr/bin/env python #coding: utf8 import sys mystr = [] 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對應,將字符合并為一個元素,用''里面的內(nèi)容分割。''里面為空,則字符之間沒有間隙 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() #使用字典的方式,實現(xiàn)case的語法功能 CMDs = {'l':leftstrip,'r':rightstrip,'b':bothsidestrip} def showmenu(): prompt = """(L)eftstrip (R)ightstrip (B)othsidestrip (Q)uit Please 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()
效果圖:
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
解決windows下Sublime Text 2 運行 PyQt 不顯示的方法分享
問題描述:PyQt 環(huán)境正常,可以使用 Windows 的 虛擬 DOS 正常運行,但在 Sublime Text 2 下使用 Ctrl + B 運行后,界面不顯示,但查看任務管理器,有 python.exe 進程。2014-06-06python3 實現(xiàn)的人人影視網(wǎng)站自動簽到
這里給大家分享的是使用Python3結合計劃任務,實現(xiàn)的人人影視網(wǎng)站自動簽到功能的代碼,非常的實用,有需要的小伙伴可以參考下2016-06-06Python實現(xiàn)決策樹并且使用Graphviz可視化的例子
今天小編就為大家分享一篇Python實現(xiàn)決策樹并且使用Graphviz可視化的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08Numpy中轉置transpose、T和swapaxes的實例講解
下面小編就為大家分享一篇Numpy中轉置transpose、T和swapaxes的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-04-04