新聞中心
Python編程語言的應(yīng)用,對于開發(fā)人員來說是一個比較好掌握的計算機程序語言。在實際應(yīng)用中,字符串的應(yīng)用是一個比較基礎(chǔ)的操作技術(shù)。我們今天就為大家詳細介紹一下有關(guān)Python字符串顯示的相關(guān)操作。

創(chuàng)新互聯(lián)公司主要從事網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)克什克騰,十余年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):028-86922220
可能是我還沒找到更好的方法,但是小遺憾的是,Python似乎目前無法支持類似shell腳本,perl所支持的標量內(nèi)插,所以在顯示的時候無法像下面,這種個人感覺,最清晰,方便的方法。
比如,用戶輸人2個變量‘basketball', 'swimming', shell或者per可以如下顯示出 I love basketball and swimming the best.
- #shell
- input = 'basketball'
- input2 = 'swimming'
- print 'I love $input and $input2 the best'
- #perl
- $input = 'basketball'
- $input2 = 'swimming'
- print 'I love $input and $input2 the best'
Python字符串顯示如何實現(xiàn)呢,有如下方法,按需選擇吧,希望以后能直接支持類似sell腳本的顯示方法,把$看作轉(zhuǎn)義符:)
- import sys
- input = sys.argv[1]
- input2 = sys.argv[2]
- s = 'I love ' + input + ' and ' + input2 + ' the best'
- print(s)
- s = 'I love %s and %s the best'%(input, input2)
- print(s)
- params= {'input': input, 'input2': input2 }
- s = 'I love %(input)s and %(input2)s the best'%params
- 13 print(s)
- from string import Template
- s = Template('I love $input and $input2 the best')
- ss =s.substitute(inputinput=input, input2input2=input2)
- print(s)
以上就是我們?yōu)榇蠹医榻B的有關(guān)Python字符串顯示的相關(guān)內(nèi)容。
網(wǎng)站名稱:Python字符串顯示實際應(yīng)用技巧分享
當前鏈接:http://m.fisionsoft.com.cn/article/ccicjpe.html


咨詢
建站咨詢
