{"id":17862,"date":"2021-08-15T10:43:40","date_gmt":"2021-08-15T05:13:40","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=17862"},"modified":"2021-11-23T18:04:32","modified_gmt":"2021-11-23T12:34:32","slug":"python-remove-first-character-example-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/","title":{"rendered":"Python remove first character | Example code"},"content":{"rendered":"\n<p>Use the <a href=\"https:\/\/tutorial.eyehunts.com\/python\/slice-operator-in-python-basics\/\">slice method<\/a> to remove the first character in Python. Here\u2019s how the code would look like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>text = 'lipsum'\nprint(text&#91;1:])\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"288\" height=\"127\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-first-character.jpg?resize=288%2C127&#038;ssl=1\" alt=\"Python remove first character\" class=\"wp-image-17982\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Removing the first x characters from a string in Python<\/strong><\/h3>\n\n\n\n<p>Use string slicing syntax <strong>string[n:]<\/strong> with n as the <a href=\"https:\/\/tutorial.eyehunts.com\/python\/how-to-print-numbers-in-same-line-in-python-example-code\/\">number <\/a>of characters to remove the first n characters from a string.<\/p>\n\n\n\n<p>Example removing the first 3 char from the given string.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>text = 'lipsum'\nprint(text&#91;3:])\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: sum<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Do comment if you have any doubts and suggestions on this Python char code.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> IDE:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>&nbsp;2021.3.3 (Community Edition)<\/p><p>Windows 10<\/p><p><strong>Python 3.10.1<\/strong><\/p><p>All<strong>&nbsp;Python Examples&nbsp;are in&nbsp;Python&nbsp;3<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Use the slice method to remove the first character in Python. Here\u2019s how the code would look like: Output: Removing the first x characters from a string in Python Use string slicing syntax string[n:] with n as the number of characters to remove the first n characters from a string. Example removing the first 3&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Python remove first character | Example code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[164],"post_series":[],"class_list":["post-17862","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-char"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python remove first character | Example code - EyeHunts<\/title>\n<meta name=\"description\" content=\"Use string slicing syntax string[n:] with n as the number of characters to remove the first n characters from a string.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python remove first character | Example code - EyeHunts\" \/>\n<meta property=\"og:description\" content=\"Use string slicing syntax string[n:] with n as the number of characters to remove the first n characters from a string.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-15T05:13:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-23T12:34:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-first-character.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/\",\"name\":\"Python remove first character | Example code - EyeHunts\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-first-character.jpg\",\"datePublished\":\"2021-08-15T05:13:40+00:00\",\"dateModified\":\"2021-11-23T12:34:32+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Use string slicing syntax string[n:] with n as the number of characters to remove the first n characters from a string.\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-first-character.jpg?fit=288%2C127&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-first-character.jpg?fit=288%2C127&ssl=1\",\"width\":288,\"height\":127},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python remove first character | Example code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python remove first character | Example code - EyeHunts","description":"Use string slicing syntax string[n:] with n as the number of characters to remove the first n characters from a string.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/","og_locale":"en_US","og_type":"article","og_title":"Python remove first character | Example code - EyeHunts","og_description":"Use string slicing syntax string[n:] with n as the number of characters to remove the first n characters from a string.","og_url":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/","og_site_name":"Tutorial","article_published_time":"2021-08-15T05:13:40+00:00","article_modified_time":"2021-11-23T12:34:32+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-first-character.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/","url":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/","name":"Python remove first character | Example code - EyeHunts","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-first-character.jpg","datePublished":"2021-08-15T05:13:40+00:00","dateModified":"2021-11-23T12:34:32+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Use string slicing syntax string[n:] with n as the number of characters to remove the first n characters from a string.","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-first-character.jpg?fit=288%2C127&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-first-character.jpg?fit=288%2C127&ssl=1","width":288,"height":127},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-first-character-example-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"Python remove first character | Example code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":17860,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-string-remove-the-first-character-example-code\/","url_meta":{"origin":17862,"position":0},"title":"Python string remove the first character | Example code","author":"Rohit","date":"November 8, 2021","format":false,"excerpt":"There are 2 ways to remove the first character from a Python string. Slicing split() function lstrip() function Example string removes the first character in Python Simple example code with different ways to remove the first char from the string. Using Slicing This method will not modify the given string.\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python string remove the first character","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/Python-string-remove-the-first-character.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":17814,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-last-character-from-string-example-code\/","url_meta":{"origin":17862,"position":1},"title":"Python remove last character from string | Example code","author":"Rohit","date":"August 12, 2021","format":false,"excerpt":"Using the slice method to Python removes the last character from the string in python. Just use the negative index value \"-1\" to retrieve items from the end of the string. Negative index starts from\u00a0-1\u00a0to -(iterable_length). Python remove the last character from the string Example Simple example code. The index\u00a0-1\u00a0gets\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python remove last character from string","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-last-character-from-string.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":17610,"url":"https:\/\/tutorial.eyehunts.com\/python\/remove-leading-and-trailing-spaces-in-python-example-code\/","url_meta":{"origin":17862,"position":2},"title":"Remove leading and trailing spaces in Python | Example code","author":"Rohit","date":"August 6, 2021","format":false,"excerpt":"Use the strip() method to remove trailing and leading spaces in Python. It will not remove internal spaces in a string. Remove leading and trailing spaces in Python Example Simple example code eliminates all whitespace before the first character and after the last character in the string. It will actually\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Remove-leading-and-trailing-spaces-in-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":17864,"url":"https:\/\/tutorial.eyehunts.com\/python\/remove-last-character-from-list-python-example-code\/","url_meta":{"origin":17862,"position":3},"title":"Remove last character from list Python | Example code","author":"Rohit","date":"August 16, 2021","format":false,"excerpt":"The slice notation [:-1] is the right approach to remove the last character from the list python. You can also use the pop() and del function to delete the last value-form list. Example remove the last element from a Python list Simple example code. Using Slicing Slice operation returns a\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Remove last character from list python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Remove-last-character-from-list-python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":17572,"url":"https:\/\/tutorial.eyehunts.com\/python\/how-to-strip-multiple-characters-python-example-code\/","url_meta":{"origin":17862,"position":4},"title":"How to strip multiple characters Python | Example code","author":"Rohit","date":"August 7, 2021","format":false,"excerpt":"Python provides a special 3 methods to remove whitespace from a string (characters) lstrip() - Remove spaces to the left of the stringrstrip() - Remove spaces to the right of the stringstrip() - Remove spaces at the beginning and at the end of the string. There are 2 more methods\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"strip multiple characters Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/strip-multiple-characters-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":17570,"url":"https:\/\/tutorial.eyehunts.com\/python\/remove-multiple-characters-from-string-python-example-code\/","url_meta":{"origin":17862,"position":5},"title":"Remove multiple characters from string Python | Example code","author":"Rohit","date":"August 6, 2021","format":false,"excerpt":"You can use replace() method or re.sub() to remove multiple characters from the string in Python. Example How to Remove multiple characters from string Python Simple example code. Use replace() method Use a for-loop to iterate through each character and call str.replace(old, new) with old as the character and new\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Remove multiple characters from string Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Remove-multiple-characters-from-string-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/17862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=17862"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/17862\/revisions"}],"predecessor-version":[{"id":22658,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/17862\/revisions\/22658"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=17862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=17862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=17862"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=17862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}