<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Indexing Strings' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Indexing Strings' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 25 May 2013 01:53:58 -0700</pubDate>
    <lastBuildDate>Sat, 25 May 2013 01:53:58 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Indexing Strings</title>
      <link>http://www.programmersheaven.com/mb/python/402203/402203/indexing-strings/</link>
      <description>In the code below, the only part I'M having trouble with is word[position]. I know this is something really simple but I've always had trouble understanding these kinds of statements. I know that it print a random letter (position) from (word). What I don't know is why or how it does that. That's the part that never seems to get explained to me. How can you just put [] around part of a statement and everything just work right? Thanks.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
# Random Access
# Demonstrates string indexing

import random

word = "index"
print "The word is: ", word, "\n"

high = len(word)
low = -len(word)

for i in range(10):
    position = random.randrange(low, high)
    print "word[", position, "]\t", word[position]

raw_input("\n\nPress the enter key to exit.")&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/402203/402203/indexing-strings/</guid>
      <pubDate>Mon, 05 Oct 2009 23:16:02 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Indexing Strings</title>
      <link>http://www.programmersheaven.com/mb/python/402203/403057/re-indexing-strings/#403057</link>
      <description>I'm not quite sure how to explain this if you already have it written out as 'word' and 'position'.  Given a string "word" and an integer "i", word[i] returns the letter in the ith position.  Remember that Python is zero-indexed, though, so for the word "index", you have &lt;br /&gt;
i -&amp;gt; 0&lt;br /&gt;
n -&amp;gt; 1&lt;br /&gt;
d -&amp;gt; 2&lt;br /&gt;
e -&amp;gt; 3&lt;br /&gt;
x -&amp;gt; 4&lt;br /&gt;
Note that there is not position 5, even though len(word) == 5.&lt;br /&gt;
&lt;br /&gt;
Also, putting '-' in an index has a special meaning in Py.  That makes your index start at the end of the word instead of at the beginning.  So, you get&lt;br /&gt;
&lt;br /&gt;
x -&amp;gt; -1&lt;br /&gt;
e -&amp;gt; -2&lt;br /&gt;
d -&amp;gt; -3&lt;br /&gt;
n -&amp;gt; -4&lt;br /&gt;
i -&amp;gt; -5&lt;br /&gt;
&lt;br /&gt;
That's nice for when you need to get to the back of a string/list, but you don't know how long it is.  I guess you could also use it to count backwards...&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/402203/403057/re-indexing-strings/#403057</guid>
      <pubDate>Thu, 08 Oct 2009 14:43:27 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Indexing Strings</title>
      <link>http://www.programmersheaven.com/mb/python/402203/403300/re-indexing-strings/#403300</link>
      <description>Thanks for the help. I really appreciate it.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/402203/403300/re-indexing-strings/#403300</guid>
      <pubDate>Thu, 08 Oct 2009 23:26:59 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>