* fix: converted single to triple backticks13 * fix: added prefix Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com> * fix: removed language in wrong place Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com> * fix: add language postfix Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com> * fix: removed language in wrong place Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>
1.1 KiB
1.1 KiB
title, localeTitle
| title | localeTitle |
|---|---|
| String Replace Method | طريقة استبدال السلاسل |
طريقة استبدال السلاسل
يتم استخدام str.replace(old, new, max) لاستبدال السلسلة الفرعية old بالسلسلة new لمجموع مرات max . هذا الأسلوب بإرجاع نسخة جديدة من السلسلة مع الاستبدال. لا يتم تغيير str السلسلة الأصلية.
أمثلة
- استبدال كافة تكرارات
"is"بـ"WAS"
string = "This is nice. This is good."
newString = string.replace("is","WAS")
print(newString)
انتاج |
ThWAS WAS nice. ThWAS WAS good.
- استبدال أول تكرارين لـ
"is"بـ"WAS"
string = "This is nice. This is good."
newString = string.replace("is","WAS", 2)
print(newString)
انتاج |
ThWAS WAS nice. This is good.
معلومات اكثر:
اقرأ المزيد حول استبدال السلسلة في مستندات Python