{"id":11601,"date":"2015-07-31T06:52:10","date_gmt":"2015-07-31T06:52:10","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=11601"},"modified":"2015-07-31T06:52:10","modified_gmt":"2015-07-31T06:52:10","slug":"python-string-indexing","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/python-string-indexing\/","title":{"rendered":"Python:  string indexing"},"content":{"rendered":"<h1>The tutor gives a Python example of string indexing.<\/h1>\n<p>In computer science, a string is a word which can include non-alphabetical characters.  An example of a string is &#8220;desk17&#8221;.<\/p>\n<p>Let&#8217;s imagine creating the variable <span style=\"font-family:monospace\">thestring<\/span> with the value <span style=\"font-family:monospace\">&#8220;desk17&#8221;<\/span>, as follows:<br \/>\n<span style=\"font-family:monospace\"><br \/>\nthestring=&#8221;desk17&#8243;<br \/>\n<\/span><br \/>\nThe characters in &#8220;desk17&#8221; can be referred to by number.  Going forward, the letter <span style=\"font-family:monospace\">d<\/span> is in position 0.  However, the string can be counted backward:  <span style=\"font-family:monospace\">7<\/span> is in position -1.  Therefore, the program<\/p>\n<p><span style=\"font-family:monospace;color:brown\"><br \/>\nthestring=&#8221;desk17&#8243;<br \/>\nprint(thestring[0])<br \/>\nprint(thestring[-1])<br \/>\n<\/span><\/p>\n<p>produces the output<br \/>\n<span style=\"font-family:monospace\"><br \/>\nd<br \/>\n7<br \/>\n<\/span><\/p>\n<p>I&#8217;ll be talking more about Python strings in future posts:)<\/p>\n<p>Source:<\/p>\n<p>Donaldson, Toby.  <u>Python<\/u>, 3rd Edition.  Peachpit Press, 2014.<\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor gives a Python example of string indexing. In computer science, a string is a word which can include non-alphabetical characters. An example of a string is &#8220;desk17&#8221;. Let&#8217;s imagine creating the variable thestring with the value &#8220;desk17&#8221;, as &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/python-string-indexing\/\"> <span class=\"screen-reader-text\">Python:  string indexing<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[930,960,958,959],"class_list":["post-11601","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-python","tag-python-negative-string-index","tag-python-string","tag-python-string-index"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/11601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=11601"}],"version-history":[{"count":17,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/11601\/revisions"}],"predecessor-version":[{"id":11618,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/11601\/revisions\/11618"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=11601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=11601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=11601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}