{"id":10203,"date":"2021-09-30T12:00:57","date_gmt":"2021-09-30T06:30:57","guid":{"rendered":"https:\/\/python-programs.com\/?p=10203"},"modified":"2021-11-22T18:34:39","modified_gmt":"2021-11-22T13:04:39","slug":"python-program-to-form-a-new-string-where-the-first-character-and-the-last-character-have-been-exchanged","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-form-a-new-string-where-the-first-character-and-the-last-character-have-been-exchanged\/","title":{"rendered":"Python Program to Form a New String where the First Character and the Last Character have been Exchanged"},"content":{"rendered":"

Strings in Python:<\/strong><\/p>\n

A string is one of the most frequent data types in any computer language. A string is a collection of characters that can be used to represent usernames, blog posts, tweets, or any other text content in your code. You can make a string and assign it to a variable by doing something like this.<\/p>\n

given_string='btechgeeks'<\/code><\/p>\n

Strings are considered immutable in Python, once created, they cannot be modified. You may, however, construct new strings from existing strings using a variety of approaches. This form of programming effort is known as string manipulation.<\/p>\n

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

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

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

given string =  hello this is btechgeeks<\/pre>\n

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

The original string before modification = hello this is btechgeeks\r\nThe new string after modification = sello this is btechgeekh<\/pre>\n

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

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

given string = this is btechgeeks online coding platform for geeks<\/pre>\n

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

Enter some random string = this is btechgeeks online coding platform for geeks\r\nThe original string before modification = this is btechgeeks online coding platform for geeks\r\nThe new string after modification = shis is btechgeeks online coding platform for geekt<\/pre>\n

Program to Form a New String where the First Character and the Last Character have been Exchanged<\/h2>\n

Below are the ways to form a new string in which the first and last characters have been swapped<\/p>\n