Cải thiện bài viết Show Lưu bài viết Cải thiện bài viết Lưu bài viết Đọc
Đầu vào: test_str = ‘g4g là 4 tất cả các geek số 1, k =‘ #, & nbsp; đầu ra: g # g là # tất cả số # geek & nbsp; Giải thích: Tất cả các số được thay thế bởi K. & NBSP; Đầu vào: test_str = ‘g4g là 4 tất cả số geek, k =‘#, & nbsp; đầu ra: g#g là#tất cả số geek & nbsp; Giải thích: Tất cả các số được thay thế bởi K. Python3Phương thức số 1: Sử dụng thay thế () + isDigit () Trong đó, chúng tôi kiểm tra các số bằng isDigit () và thay thế () được sử dụng để thực hiện nhiệm vụ thay thế các số bằng K. The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks2 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks3 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks4 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks5 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks6 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks7 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks8 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks9 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks0 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks1 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks3 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks3 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks4 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks5 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks6 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks7 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks8 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks9 0
The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks
Đầu ra Phương thức số 2: Sử dụng regex () + sub ()Trong đó, regex thích hợp được sử dụng để xác định các chữ số và sub () được sử dụng để thực hiện thay thế. Phương thức số 1: Sử dụng thay thế () + isDigit () Trong đó, chúng tôi kiểm tra các số bằng isDigit () và thay thế () được sử dụng để thực hiện nhiệm vụ thay thế các số bằng K. The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks2 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks3 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks4 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks5 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks6 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks7 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks8 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks9 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks0 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks1 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks3 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks3
The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks
Python3Phương thức số 1: Sử dụng thay thế () + isDigit () Trong đó, chúng tôi kiểm tra các số bằng isDigit () và thay thế () được sử dụng để thực hiện nhiệm vụ thay thế các số bằng K. The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks2 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks3 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks4 8The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks3 0The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks5 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks6 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks7 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks8 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks9 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks0 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks1 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks3 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks3 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks4 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks5 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks6 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks7 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks8 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks9 0
The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks5 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks6 7 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks8 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks9 The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks0
Tôi muốn tạo một chuỗi mới bằng cách thay thế các chữ số bằng The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks00 ví dụ:
... Nhưng số The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks01 có thể là bất kỳ chữ số nào chẳng hạn The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks02 Tôi có thể cho The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks03 một ký tự đại diện để mong đợi bất kỳ chữ số nào không? Như The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks04 Hay tôi phải tạo ra một biểu hiện thông thường?
Johnsyweb Huy hiệu vàng 133K2323 gold badges180 silver badges244 bronze badges hỏi ngày 29 tháng 9 năm 2013 lúc 23:23Sep 29, 2013 at 23:23
1 Sử dụng các biểu thức thông thường:
The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks05 khớp với bất kỳ số 0-9. The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks06 thay thế (các) số bằng The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks00 Đã trả lời ngày 29 tháng 9 năm 2013 lúc 23:24Sep 29, 2013 at 23:24
TerryaterryaTerryA 57.4K11 Huy hiệu vàng117 Huy hiệu bạc140 Huy hiệu đồng11 gold badges117 silver badges140 bronze badges Bạn không thể; The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks08 chỉ làm việc với văn bản theo nghĩa đen. Để thay thế các mẫu, hãy sử dụng các biểu thức thông thường:
Demo:
Đã trả lời ngày 29 tháng 9 năm 2013 lúc 23:24Sep 29, 2013 at 23:24
Martijn Pieters ♦ Martijn Pieters♦Martijn Pieters 997K279 Huy hiệu vàng3923 Huy hiệu bạc3264 Huy hiệu Đồng279 gold badges3923 silver badges3264 bronze badges Chỉ cho sự đa dạng, một số phương pháp không phải là REGEX:
Hoặc nếu bạn cần nhóm nhiều chữ số:
. Đã trả lời ngày 29 tháng 9 năm 2013 lúc 23:30Sep 29, 2013 at 23:30
DSMDSMDSM 330K62 Huy hiệu vàng575 Huy hiệu bạc481 Huy hiệu Đồng62 gold badges575 silver badges481 bronze badges Một giải pháp sử dụng The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks09 (nguồn):
Đã trả lời ngày 4 tháng 12 năm 2019 lúc 23:30Dec 4, 2019 at 23:30
LomaphlomaphLoMaPh 1.2362 huy hiệu vàng17 Huy hiệu bạc32 Huy hiệu đồng2 gold badges17 silver badges32 bronze badges Nếu bạn muốn xóa tất cả các chữ số trong chuỗi, bạn có thể thực hiện bằng cách sử dụng The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks09 (xóa số khỏi chuỗi): The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks0
Đã trả lời ngày 25 tháng 4 năm 2020 lúc 16:16Apr 25, 2020 at 16:16
AhmedahmedAhmed Phù hiệu đồng 4177 bronze badges The original string is : G4G is 4 all No. 1 Geeks The resultant string : G@G is @ all No. @ Geeks1 Đã trả lời ngày 15 tháng 4 năm 2020 lúc 7:24Apr 15, 2020 at 7:24
2 Làm thế nào tôi có thể thay thế số bằng chuỗi bằng Python?Phương thức số 1: Sử dụng thay thế () + isDigit () Trong này, chúng tôi kiểm tra số bằng isDigit () và thay thế () được sử dụng để thực hiện nhiệm vụ thay thế các số bằng K.Using replace() + isdigit()
In this, we check for numerics using isdigit() and replace() is used to perform the task of replacing the numbers by K.
Có phải thay thế công việc với các chuỗi trong Python?Thay thế () Phương thức Python, bạn có thể thay thế mọi phiên bản của một ký tự cụ thể bằng một ký tự mới.Bạn thậm chí có thể thay thế toàn bộ chuỗi văn bản bằng một dòng văn bản mới mà bạn chỉ định.Phương thức .replace () trả về một bản sao của một chuỗi.The . replace() method returns a copy of a string. |