Content-Length: 318171 | pFad | http://github.com/farhanjaved47/python/commit/0672bb6e9961068060ae0121860b15e0d862e73c

B1 Sequence Types in Python · farhanjaved47/python@0672bb6 · GitHub
Skip to content

Commit 0672bb6

Browse files
committed
Sequence Types in Python
1 parent 074e9e2 commit 0672bb6

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

SequenceTypes.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
def main():
2+
myList = [1, 2, 3, 4, 5] # this is a list. Initialized by square brackets []
3+
myList[4] = 7 # list are mutable. This means that you can change their content after initialization.
4+
5+
for i in myList:
6+
print("Value in list : " + str(i))
7+
8+
myTuple = (1, 2, 3, 4, 5) # this is a tuple. Initialized by round brackets ( )
9+
10+
for i in myTuple:
11+
print("Value in tuple: " + str(i))
12+
13+
# myTuple[4] = 8 # Tuples are immutable. Running this command will throw an error.
14+
15+
# Tuples preferred unless you know for sure that you have to change the values.
16+
17+
oneArgRange = range(5) # this call only gives the start parameter to range
18+
for i in oneArgRange:
19+
print("value in one argument range : " + str(i))
20+
21+
twoArgRange = range(5, 10) # this call gives the start and end parameter to range
22+
for i in twoArgRange:
23+
print("value in two argument range : " + str(i))
24+
25+
fullArgRange = range(5, 50, 5) # this call gives start, end and the step parameter
26+
for i in fullArgRange:
27+
print("value in complete argument range : " + str(i))
28+
29+
# end parameter values are non inclusive in range.
30+
# range is also immutable
31+
listFromRange = list(range(1, 100, 10)) # mutable lists can be made from immutable range
32+
listFromRange[2] = 0
33+
for i in listFromRange:
34+
print("Value in List made from range : " + str(i))
35+
36+
# Dictionaries are a structure of key value pairs and are mutable
37+
38+
myDict = {'keyOne': 1, 'keyTwo': 2, 'keyThree': 3, 'keyFour': 4, 'keyFive': 5}
39+
40+
myDict['keyThree'] = 33
41+
for key, value in myDict.items() :
42+
print("Printing dictionary key value pairs : " + key + " " + str(value))
43+
44+
main()

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/farhanjaved47/python/commit/0672bb6e9961068060ae0121860b15e0d862e73c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy