{"id":10293,"date":"2021-09-30T12:00:50","date_gmt":"2021-09-30T06:30:50","guid":{"rendered":"https:\/\/python-programs.com\/?p=10293"},"modified":"2021-11-22T18:34:40","modified_gmt":"2021-11-22T13:04:40","slug":"python-program-to-form-a-new-string-made-of-the-first-2-and-last-2-characters-from-a-given-string","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-form-a-new-string-made-of-the-first-2-and-last-2-characters-from-a-given-string\/","title":{"rendered":"Python Program to Form a New String Made of the First 2 and Last 2 characters From a Given String"},"content":{"rendered":"

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

\u201cString is a character collection or array\u201d<\/strong><\/p>\n

Well in Python too, for the string data type, we say the same definition. The string is a sequenced character array and is written within single, double, or three quotes. Also, Python does not have the data type character, thus it is used as a string of length 1 if we write \u2018r’.<\/p>\n

Given a string, the task is to form a new string which is made of the First 2 and Last 2 characters From a Given String in Python.<\/p>\n

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

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

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

given string =BTechGeeks<\/pre>\n

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

BTks<\/pre>\n

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

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

given string =AplusTopper<\/pre>\n

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

Aper<\/pre>\n

Program to Form a New String Made of the First 2 and Last 2 characters From a Given String<\/h2>\n

Below is the full approach to form a new string which is made of the First 2 and Last 2 characters From a Given String in Python.<\/p>\n