Phương thức chuỗi Python. Bộ 3 [strip, lstrip, rstrip, min, max, maketrans, translate, replace & expandtabs[]]
Cải thiện bài viết
Lưu bài viết
Thích bài viết
- Độ khó. Dễ dàng
- Cập nhật lần cuối. 28 tháng 7 năm 2022
Cải thiện bài viết
Lưu bài viết
Một số phương thức chuỗi được trình bày trong các bộ bên dưới.
Phương thức chuỗi Phần 1
Phương thức chuỗi Phần 2
Các phương thức khác sẽ được thảo luận trong bài viết này
1. strip[]:- This method is used to delete all the leading and trailing characters mentioned in its argument.
2. lstrip[]. - Phương thức này dùng để xóa tất cả các ký tự đứng đầu được nhắc đến trong đối số của nó.
3. rstrip[]. - Phương thức này dùng để xóa tất cả các ký tự đuôi được nhắc đến trong đối số của nó.
con trăn
The string after translation using mapped elements is : aeeksbcraeeks4
The string after translation using mapped elements is : aeeksbcraeeks5
The string after translation using mapped elements is : aeeksbcraeeks6
The string after translation using mapped elements is : aeeksbcraeeks7
The string after translation using mapped elements is : aeeksbcraeeks8
The minimum value character is : e The maximum value character is : s0
The minimum value character is : e The maximum value character is : s1
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s3
The minimum value character is : e The maximum value character is : s4
The minimum value character is : e The maximum value character is : s5
The string after translation using mapped elements is : aeeksbcraeeks7
The minimum value character is : e The maximum value character is : s7
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s3
The string after translation using mapped elements is : aeeksbcraeeks6______91
The string after translation using mapped elements is : aeeksbcraeeks2
The string after translation using mapped elements is : aeeksbcraeeks3
The minimum value character is : e The maximum value character is : s0
The string after translation using mapped elements is : aeeksbcraeeks5
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s3
The string after translation using mapped elements is : aeeksbcraeeks8
The minimum value character is : e The maximum value character is : s5
The string after translation using mapped elements is : aeeksbcraeeks7
The minimum value character is : e The maximum value character is : s7
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s3____96____215
The string after translation using mapped elements is : aeeksbcraeeks2
The string after translation using mapped elements is : aeeksbcraeeks3
The minimum value character is : e The maximum value character is : s0
The minimum value character is : e The maximum value character is : s19
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s3
The minimum value character is : e The maximum value character is : s82
The minimum value character is : e The maximum value character is : s5
The string after translation using mapped elements is : aeeksbcraeeks7
The minimum value character is : e The maximum value character is : s7
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s3
The string after translation using mapped elements is : aeeksbcraeeks6______289
The string after translation using mapped elements is : aeeksbcraeeks2
The string after translation using mapped elements is : aeeksbcraeeks3
Đầu ra.
The minimum value character is : e The maximum value character is : s6
4. tối thiểu[“chuỗi”]. - Hàm này trả về bảng chữ cái giá trị nhỏ nhất từ chuỗi.
5. tối đa["chuỗi"]. - Hàm này trả về bảng chữ cái giá trị lớn nhất từ chuỗi.
con trăn
The string after translation using mapped elements is : aeeksbcraeeks4
The string after translation using mapped elements is : aeeksbcraeeks43
The string after translation using mapped elements is : aeeksbcraeeks6
The string after translation using mapped elements is : aeeksbcraeeks7
The string after translation using mapped elements is : aeeksbcraeeks46
The minimum value character is : e The maximum value character is : s0
The string after translation using mapped elements is : aeeksbcraeeks48
The string after translation using mapped elements is : aeeksbcraeeks49
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s3
The string after translation using mapped elements is : aeeksbcraeeks52
The string after translation using mapped elements is : aeeksbcraeeks53
The string after translation using mapped elements is : aeeksbcraeeks54
The minimum value character is : e The maximum value character is : s3
The string after translation using mapped elements is : aeeksbcraeeks6
The string after translation using mapped elements is : aeeksbcraeeks57
The minimum value character is : e The maximum value character is : s0
The string after translation using mapped elements is : aeeksbcraeeks59
The string after translation using mapped elements is : aeeksbcraeeks60
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s3
The string after translation using mapped elements is : aeeksbcraeeks63
The string after translation using mapped elements is : aeeksbcraeeks53
The string after translation using mapped elements is : aeeksbcraeeks65
The minimum value character is : e The maximum value character is : s3
The string after translation using mapped elements is : aeeksbcraeeks6
The string after translation using mapped elements is : aeeksbcraeeks57
Đầu ra.
The minimum value character is : e The maximum value character is : s
6. maketrans[]. - Dùng để ánh xạ nội dung của chuỗi 1 với chuỗi 2 với các chỉ số tương ứng để dịch sau bằng translate[].
7. dịch[]. - Điều này được sử dụng để hoán đổi các phần tử chuỗi được ánh xạ với sự trợ giúp của maketrans[].
con trăn
The string after translation using mapped elements is : aeeksbcraeeks4
The string after translation using mapped elements is : aeeksbcraeeks70
The string after translation using mapped elements is : aeeksbcraeeks71
The string after translation using mapped elements is : aeeksbcraeeks72____973
The string after translation using mapped elements is : aeeksbcraeeks74
The string after translation using mapped elements is : aeeksbcraeeks75
The minimum value character is : e The maximum value character is : s0
The string after translation using mapped elements is : aeeksbcraeeks6
The string after translation using mapped elements is : aeeksbcraeeks7
The string after translation using mapped elements is : aeeksbcraeeks46
The minimum value character is : e The maximum value character is : s0
The string after translation using mapped elements is : aeeksbcraeeks81
The string after translation using mapped elements is : aeeksbcraeeks7
The string after translation using mapped elements is : aeeksbcraeeks83
The string after translation using mapped elements is : aeeksbcraeeks84
The string after translation using mapped elements is : aeeksbcraeeks7
The string after translation using mapped elements is : aeeksbcraeeks86
The minimum value character is : e The maximum value character is : s0
The string after translation using mapped elements is : aeeksbcraeeks88
The string after translation using mapped elements is : aeeksbcraeeks89
The string after translation using mapped elements is : aeeksbcraeeks7
The minimum value character is : e The maximum value character is : s01
The minimum value character is : e The maximum value character is : s0
The minimum value character is : e The maximum value character is : s03
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s05
The minimum value character is : e The maximum value character is : s2
The string after translation using mapped elements is : aeeksbcraeeks6
The minimum value character is : e The maximum value character is : s08
Đầu ra.
The string after translation using mapped elements is : aeeksbcraeeks
Trong đoạn mã trên, 'g' được thay thế bằng a, 'f' được thay thế bằng b và 'o' được thay thế bằng 'c' trong chuỗi bằng hàm dịch.
8. thay thế[]. - Hàm này dùng để thay thế chuỗi con bằng một chuỗi con mới trong chuỗi. Hàm này có 3 đối số. Chuỗi để thay thế, chuỗi mới sẽ thay thế và giá trị tối đa biểu thị giới hạn để thay thế hành động [theo mặc định là không giới hạn].
con trăn
The string after translation using mapped elements is : aeeksbcraeeks4
The minimum value character is : e The maximum value character is : s10
The minimum value character is : e The maximum value character is : s0
The string after translation using mapped elements is : aeeksbcraeeks6
The string after translation using mapped elements is : aeeksbcraeeks7
The minimum value character is : e The maximum value character is : s14
The minimum value character is : e The maximum value character is : s0
The string after translation using mapped elements is : aeeksbcraeeks81
The string after translation using mapped elements is : aeeksbcraeeks7
The minimum value character is : e The maximum value character is : s18
The string after translation using mapped elements is : aeeksbcraeeks84
The string after translation using mapped elements is : aeeksbcraeeks7
The minimum value character is : e The maximum value character is : s21
The minimum value character is : e The maximum value character is : s0
The minimum value character is : e The maximum value character is : s23
The minimum value character is : e The maximum value character is : s24
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s3
The minimum value character is : e The maximum value character is : s27
The minimum value character is : e The maximum value character is : s5
The string after translation using mapped elements is : aeeksbcraeeks7
The minimum value character is : e The maximum value character is : s7
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s3
The string after translation using mapped elements is : aeeksbcraeeks6______034
The minimum value character is : e The maximum value character is : s35
The minimum value character is : e The maximum value character is : s36
Đầu ra.
The minimum value character is : e The maximum value character is : s1
Phương pháp này được đóng góp bởi Chinmoy Lenka
9. thẻ mở rộng[]. - Nó được sử dụng để thay thế tất cả các ký tự tab[“\t”] bằng khoảng trắng hoặc đơn giản là khoảng trắng sử dụng kích thước tab đã cho, đây là tùy chọn cung cấp.
Cú pháp. sợi dây. tabsize[tabsize]
Thông số. Chỉ định số lượng ký tự được thay thế cho một ký tự tab. Theo mặc định, hàm lấy kích thước tab là 8.
Giá trị trả về. Một chuỗi trong đó tất cả các ký tự tab được thay thế bằng dấu cách.
Python3
The minimum value character is : e The maximum value character is : s37
The string after translation using mapped elements is : aeeksbcraeeks72
The string after translation using mapped elements is : aeeksbcraeeks7
The minimum value character is : e The maximum value character is : s40
The minimum value character is : e The maximum value character is : s0
The minimum value character is : e The maximum value character is : s42
The minimum value character is : e The maximum value character is : s2
The minimum value character is : e The maximum value character is : s44
The minimum value character is : e The maximum value character is : s0
The minimum value character is : e The maximum value character is : s46
_______02____048____035____957
The minimum value character is : e The maximum value character is : s0
The minimum value character is : e The maximum value character is : s52
The minimum value character is : e The maximum value character is : s2____048____055
The string after translation using mapped elements is : aeeksbcraeeks57
Đầu ra.
The minimum value character is : e The maximum value character is : s8
Ghi chú cá nhân của tôi arrow_drop_up
Tiết kiệm