Bài viết này trình bày một vấn đề như vậy về việc xóa ký tự thứ i khỏi chuỗi và nói về các giải pháp khả thi có thể được sử dụng để đạt được chúng bằng Python
Xóa ký tự thứ i khỏi chuỗi bằng phương thức gốc
Trong phương pháp này, người ta chỉ cần chạy một vòng lặp Python và nối thêm các ký tự khi chúng xuất hiện và tạo một chuỗi mới từ chuỗi hiện có trừ khi chỉ mục là i.
Python3
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks8
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks9
The string after removal of i'th character : GeksForGeeks0
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks1
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks2
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks3
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks4
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks5
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks8
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks9
The string after removal of i'th character : GeksForGeeks0
The string after removal of i'th character : GeksForGeeks1
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character : GeksForGeeks3
The string after removal of i'th character : GeksForGeeks4
The string after removal of i'th character : GeksForGeeks5
The string after removal of i'th character : GeksForGeeks0
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character : GeksForGeeks0
The string after removal of i'th character : GeksForGeeks9
The string after removal of i'th character : GeksForGeeks0
The string after removal of i'th character : GeksForGeeks1
The string after removal of i'th character : GeksForGeeks2
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character : GeksForGeeks4
The string after removal of i'th character : GeksForGeeks9
The string after removal of i'th character : GeksForGeeks6
đầu ra
The string after removal of i'th character : GeksForGeeks
Xóa ký tự thứ i khỏi chuỗi bằng cách sử dụng str. thay thế[]
các str. replace[] có thể được sử dụng để thực hiện tác vụ xóa vì chúng ta có thể thay thế chỉ mục cụ thể bằng char trống và do đó giải quyết được sự cố.
Hạn chế. Hạn chế chính của phương pháp này là nó không thành công trong trường hợp có các bản sao trong một chuỗi khớp với ký tự tại vị trí. tôi. replace[] thay thế tất cả các lần xuất hiện của một ký tự cụ thể và do đó sẽ thay thế tất cả các lần xuất hiện của tất cả các ký tự tại vị trí i. Đôi khi chúng ta vẫn có thể sử dụng chức năng này nếu ký tự thay thế xuất hiện lần đầu tiên trong chuỗi.
Python3
The string after removal of i'th character : GeksForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks8
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks9
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks42
The string after removal of i'th character : GeksForGeeks0
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks45____246
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks47
The string after removal of i'th character : GeksForGeeks1
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks49
The string after removal of i'th character : GeksForGeeks2
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks62
The string after removal of i'th character : GeksForGeeks9
The string after removal of i'th character : GeksForGeeks6
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks65
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks66
The string after removal of i'th character : GeksForGeeks0
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks45
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks70
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks71
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks72
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks73
The string after removal of i'th character : GeksForGeeks1
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks75
The string after removal of i'th character : GeksForGeeks2
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks78
The string after removal of i'th character : GeksForGeeks9
The string after removal of i'th character : GeksForGeeks6
đầu ra
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks
Xóa ký tự thứ i khỏi chuỗi bằng cách sử dụng lát cắt + nối
Người ta có thể sử dụng cắt chuỗi và cắt chuỗi trước pos i và cắt sau pos i. Sau đó, sử dụng phép nối chuỗi của cả hai, ký tự thứ i có thể bị xóa khỏi chuỗi.
Python3
The string after removal of i'th character : GeksForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks8
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks9
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks86
The string after removal of i'th character : GeksForGeeks0
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks89
The string after removal of i'th character : GeksForGeeks3
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks91
The string after removal of i'th character : GeksForGeeks9
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks93____894
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks95
The string after removal of i'th character : GeksForGeeks1
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks97
The string after removal of i'th character : GeksForGeeks2
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character : GeksForGeeks4
The string after removal of i'th character : GeksForGeeks9
The string after removal of i'th character : GeksForGeeks6
đầu ra
The string after removal of i'th character : GeksForGeeks
Xóa ký tự thứ i khỏi chuỗi bằng cách sử dụng str. tham gia [] và hiểu danh sách
Trong phương pháp này, trước tiên, mỗi phần tử của chuỗi được chuyển đổi thành từng phần tử của danh sách, sau đó mỗi phần tử trong số chúng được nối để tạo thành một chuỗi ngoại trừ chỉ mục đã chỉ định.
Python3
The string after removal of i'th character : GeksForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks8
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks9
The string after removal of i'th character : GeksForGeeks08
The string after removal of i'th character : GeksForGeeks0
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks01_______02
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks3
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks4
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks5
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6______07
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks08
The string after removal of i'th character : GeksForGeeks0
The string after removal of i'th character : GeksForGeeks1
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character : GeksForGeeks3
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks13
The string after removal of i'th character : GeksForGeeks1
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks97
The string after removal of i'th character : GeksForGeeks2
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character : GeksForGeeks4
The string after removal of i'th character : GeksForGeeks9
The string after removal of i'th character : GeksForGeeks6
đầu ra.
The string after removal of i'th character : GeksForGeeks
Xóa ký tự cụ thể khỏi chuỗi bằng translate[]
Trong phương pháp này, chúng tôi đã xóa 123 khỏi Geeksforgeeks bằng cách sử dụng chuỗi. dịch[].
Python3
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks21
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks7
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks23
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks24
The string after removal of i'th character : GeksForGeeks2
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks6
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks21
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks28
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks29
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks30
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks31
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks2
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks3
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks4
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks35
The string after removal of i'th character[ doesn't work] : GksForGks The string after removal of i'th character[works] : GeekForGeeks36