自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Python字符串顯示實際應(yīng)用技巧分享

開發(fā) 后端
Python字符串顯示的相關(guān)應(yīng)用方法將會在這篇文章中為大家詳細(xì)介紹,我們可以通過這里介紹的內(nèi)容充分掌握這一應(yīng)用技術(shù)。

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

可能是我還沒找到更好的方法,但是小遺憾的是,Python似乎目前無法支持類似shell腳本,perl所支持的標(biāo)量內(nèi)插,所以在顯示的時候無法像下面,這種個人感覺,最清晰,方便的方法。
比如,用戶輸人2個變量‘basketball', 'swimming', shell或者per可以如下顯示出 I love basketball and swimming the best.

  1. #shell  
  2. input = 'basketball' 
  3. input2 = 'swimming' 
  4. print 'I love $input and $input2 the best'  
  5. #perl  
  6. $input = 'basketball' 
  7. $input2 = 'swimming' 
  8. print 'I love $input and $input2 the best' 

Python字符串顯示如何實現(xiàn)呢,有如下方法,按需選擇吧,希望以后能直接支持類似sell腳本的顯示方法,把$看作轉(zhuǎn)義符:)

  1. import sys  
  2. input = sys.argv[1]  
  3. input2 = sys.argv[2]  
  4. s = 'I love ' + input + ' and ' + input2 + ' the best'  
  5. print(s)  
  6. s = 'I love %s and %s the best'%(input, input2)  
  7. print(s)  
  8. params= {'input': input, 'input2': input2 }  
  9. s = 'I love %(input)s and %(input2)s the best'%params  
  10. 13 print(s)  
  11. from string import Template  
  12. s = Template('I love $input and $input2 the best')  
  13. ss =s.substitute(inputinput=input, input2input2=input2)  
  14. print(s) 

以上就是我們?yōu)榇蠹医榻B的有關(guān)Python字符串顯示的相關(guān)內(nèi)容。

【編輯推薦】

  1. Python Socket編程實現(xiàn)網(wǎng)絡(luò)編程
  2. Python base64模塊基本概念總結(jié)
  3. Python取得文件列表基本應(yīng)用方式淺談
  4. Python抓取網(wǎng)頁內(nèi)容應(yīng)用代碼分析
  5. Python編碼規(guī)范基本內(nèi)容簡介
責(zé)任編輯:曹凱 來源: 博客園
相關(guān)推薦

2009-12-11 13:16:04

PHP查詢字符串

2010-05-21 17:22:22

2010-03-01 13:06:49

WCF繼承

2009-09-01 17:50:23

C#截取字符串

2010-02-01 17:09:07

C++鏈表操作

2010-04-09 18:15:47

Oracle 字符串

2010-03-01 17:52:03

WCF選擇綁定

2010-03-05 16:09:44

Python中文字符

2024-09-06 17:32:55

字符串Python

2010-03-16 10:58:35

Python字符串

2010-03-16 16:22:36

Python字符串

2025-02-21 12:30:00

字符串前端JavaScript

2010-03-09 16:16:55

Python字符串

2009-12-08 16:33:45

PHP unpack函

2010-03-03 16:57:28

Python字符

2010-03-11 19:34:57

Python字符串

2009-12-15 10:23:23

Ruby應(yīng)用技巧

2010-03-22 18:53:53

Python格式化字符

2009-12-18 09:52:40

Ruby字符串處理函數(shù)

2023-12-11 07:33:05

Go語言字符技巧
點贊
收藏

51CTO技術(shù)棧公眾號