3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
http://pythoncat.blogspot.tw/2014/11/python.html 字串處理  1. print() 字串列印 Ex: print (“Hello, Daisy!”) Hello, Daisy!  2. replace() 字串取代 Ex1:  >>> s = “$1,000.00” >>> s1 = s.replace(“$”,””) >>> print(s1) 1,000.00 Ex2(替代多個字元): >>> s = “$1,000.00” >>> s1 = s.replace(“$”,””) >>> s = “$1,000.00” >>> s1 = s.replace(“$”,””).replace(“,”,””) >>> print(s1) 1000.00  3. strip() 字串移除空白 Ex1(移除頭尾側空白):  >>> s = ”  $1,000.00  “ >>> s1 = s.strip() >>> print(s1) $1,000.00 Ex2(僅移除右側空白): s = ”  $1,000.00  “ >>> s1 = s.rstrip() >>> print(s1)   $1,000.00 Ex3(僅移除左側空白): s = ”  $1,000.00  “ >>> s1 = s.lstrip() >>> print(s1) $1,000.00    4. end=”” 移除換行 python 3 於 print 後,會自動換行,像是自動帶了 C 語言的 n。若要移除換行符號請參考範例: 移除換行符號前: for i in range(1,5): print (i) 1 2 3 4 移除換行符號後: for i in range(1,5): print (i,end=”) 1234 美食

本文由daisyyohoho提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦