avatarJim McAulay🍁 I'm nobody. Are you a nobody too?

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1479

Abstract

reates a range object. Consisting of 10 items starting at 0. The above command will put the range object into a tuple so that it can be printed.</p><div id="67fe"><pre>(<span class="hljs-number">0,1,2,3</span>,<span class="hljs-number">4,5,6,7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>) </pre></div><p id="194d">if you want to produce the numbers 1 to 10. Start the sequence at the second position or index 1 and count up to but not including 11.</p><div id="031c"><pre><span class="hljs-built_in">print</span> (<span class="hljs-built_in">tuple</span> (<span class="hljs-built_in">range</span> (<span class="hljs-number">1</span>,<span class="hljs-number">11</span>)) <span class="hljs-comment">#will return tuple contain numbers 1-10</span></pre></div><p id="e5da">if you want the 4th item in a string. You put the index of that number between square brackets. Remember the first item is 0. The index of the first item is 0 or A. The index of the second item is 1 or B. The index of the 4th item is 3 or D.</p><div id="e9da"><pre><span class="hljs-attr">tup</span> = (<span class="hljs-string">"ABCDEFG"</span>) <span class="hljs-comment"># index ( 0123456 )</span> <span class="hljs-comment">#)ordinal ( 1234567 )</span></pre></div><div id="23c2"><pre><span class="hljs-keyword">print</span> (tup [<span class="hljs-number">3</span>]) will <span class="hljs-keyword">return</span> D</pre></div><p id="572e">This works for strings, list

Options

s or tuples</p><div id="9b66"><pre>[<span class="hljs-string">"A"</span>,<span class="hljs-string">"B"</span>,<span class="hljs-string">"C"</span>] <span class="hljs-built_in">item</span> <span class="hljs-keyword">at</span> index <span class="hljs-number">1</span> <span class="hljs-keyword">is</span> B [<span class="hljs-string">"A"</span>,<span class="hljs-string">"B"</span>,<span class="hljs-string">"C"</span>] <span class="hljs-built_in">item</span> <span class="hljs-keyword">at</span> index <span class="hljs-number">0</span> <span class="hljs-keyword">is</span> A (<span class="hljs-string">"ABC"</span>,) <span class="hljs-built_in">item</span> <span class="hljs-keyword">at</span> index <span class="hljs-number">2</span> <span class="hljs-keyword">is</span> C</pre></div><p id="ca0c"><a href="https://readmedium.com/c4d5fe0b9b6c?source=post_page-----acf8106ab83d----------------------">Jim McAulay🍁</a> says:</p><p id="8707">A woman goes to a funeral home and says that she wants her husband to be buried in a blue suit instead of the brown one he is wearing. At the funeral he is wearing a lovely blue suit. She goes to the director and asks how much she owes him for the suit.</p><p id="b060">“Funny thing happened” he said. “A few hours after you left another woman came in and wanted her husband to be buried in a brown suit and since they were both the same size we just switched the heads.”</p><p id="9752">47–48</p><p id="b4d1">15–14</p></article></body>

Indexing In Python

In python the index of a sequence of items starts at 0

source: Unknown author / Public domain https://commons.wikimedia.org/wiki/File:2%D0%A2%D0%B5%D0%BB%D0%BE.jpg

In Python the index of a sequence of items starts at 0. When you create a string, list or tuple the first item is item 0.

Why ?

Think of a series of numbers starting with a negative number and becoming positive.

-3, -2, -1, 0, 1, 2, 3,

The fourth number in the series is at index 0

-3 + 1 = -2,  -2 +1 = 1,  -1+1 = 0, 0+1 = 1  1+1 = 2

if you want to print 10 numbers

print (tuple (range (10))

The range command creates a range object. Consisting of 10 items starting at 0. The above command will put the range object into a tuple so that it can be printed.

(0,1,2,3,4,5,6,7,8,9)

if you want to produce the numbers 1 to 10. Start the sequence at the second position or index 1 and count up to but not including 11.

print (tuple (range (1,11)) #will return tuple contain numbers 1-10

if you want the 4th item in a string. You put the index of that number between square brackets. Remember the first item is 0. The index of the first item is 0 or A. The index of the second item is 1 or B. The index of the 4th item is 3 or D.

tup =     ("ABCDEFG")
# index   ( 0123456 )
#)ordinal ( 1234567 )
print (tup [3]) will return D

This works for strings, lists or tuples

["A","B","C"]  item at index 1 is B
["A","B","C"]  item at index 0 is A
("ABC",)  item at index 2 is C

Jim McAulay🍁 says:

A woman goes to a funeral home and says that she wants her husband to be buried in a blue suit instead of the brown one he is wearing. At the funeral he is wearing a lovely blue suit. She goes to the director and asks how much she owes him for the suit.

“Funny thing happened” he said. “A few hours after you left another woman came in and wanted her husband to be buried in a brown suit and since they were both the same size we just switched the heads.”

47–48

15–14

Technology
Python
Jim Mcaulay
Illumination
Programming For Beginners
Recommended from ReadMedium