{"id":4244,"date":"2022-03-09T16:51:56","date_gmt":"2022-03-09T16:51:56","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4244"},"modified":"2022-03-09T17:31:07","modified_gmt":"2022-03-09T17:31:07","slug":"using-strings-characters","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/strings-python\/using-strings-characters","title":{"rendered":"Using Strings-Characters"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">String Characters<\/h4>\n\n\n\n<p>A string is a <strong>list<\/strong> of characters<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>senders_phone_number = \"+4407973123456\";\nif (senders_phone_number&#91;0] == '+')<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Negative indices<\/h5>\n\n\n\n<p>Negative indices count backward from the end of the string, so string_name[-1] is the last character of the string, etc<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Altering characters in a string<\/h4>\n\n\n\n<p>Strings are immutable in Python, so you can&#8217;t do this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_string&#91;0] = 'a'    #&lt;&lt;This won't work!<\/code><\/pre>\n\n\n\n<p>you have to do this instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>my_string = \"a\" + my_string&#91;1:]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Work through each character in a string<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>for next_character in my_string:\r\n  print(next_character)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>String Characters A string is a list of characters Negative indices Negative indices count backward from the end of the string, so string_name[-1] is the last character of the string, etc Altering characters in a string Strings are immutable in Python, so you can&#8217;t do this: you have to do this instead: Work through each [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[319],"tags":[],"class_list":["post-4244","post","type-post","status-publish","format-standard","hentry","category-strings-python"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4244"}],"version-history":[{"count":6,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4244\/revisions"}],"predecessor-version":[{"id":4279,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4244\/revisions\/4279"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}