程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python string replace function

編輯:Python

Hello everyone , I meet you again , I'm your friend, Quan Jun .

python String substitution replace function

replace(old, new, count)
  • old, Old character or string
  • new, New character or string
  • count, Maximum replacement quantity , Count from the starting position , Replace all... By default
  • Be careful :replace Function to replace the string , Does not affect the original string

Example 1: Replace all... By default

s1 = '2019.10.30'
s2 = s1.replace('.', '-')
s2
'2019-10-30'
s1 # Does not affect the original string 
'2019.10.30'

Example 2: Specify replacement quantity

s1 = '2019.10.30'
s2 = s1.replace('.', '-',1)
s2
'2019-10.30'

Example 3: Replace string

s1 = '2019.10.30'
s2 = s1.replace('19', '20')
s2
'2020.10.30'

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/133975.html Link to the original text :https://javaforall.cn


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved