{"id":4154,"date":"2023-10-24T18:59:26","date_gmt":"2023-10-24T13:29:26","guid":{"rendered":"https:\/\/python-programs.com\/?p=4154"},"modified":"2023-11-10T11:56:58","modified_gmt":"2023-11-10T06:26:58","slug":"remove-last-n-characters-from-string-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/remove-last-n-characters-from-string-in-python\/","title":{"rendered":"Remove Last N Characters from String in Python"},"content":{"rendered":"

Strings are one of the most commonly used types in Python. We can easily make them by enclosing characters in quotes. Python considers single quotes to be the same as double quotes. String creation is as easy as assigning a value to a variable.<\/p>\n

Given a string, the task is to remove last n characters from string.<\/p>\n

Examples:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

string=\"BTechGeeks\" n=3<\/pre>\n

Output:<\/strong><\/p>\n

BTechGe<\/pre>\n

Remove Last N Characters from String<\/h2>\n

There are several ways to remove last n characters from string some of them are:<\/p>\n