8.6 KiB
8.6 KiB
In [ ]:
range(0,11)In [ ]:
# Notice how 11 is not included, up to but not including 11, just like slice notation!
list(range(0,11))In [ ]:
list(range(0,12))In [ ]:
# Third parameter is step size!
# step size just means how big of a jump/leap/step you
# take from the starting number to get to the next number.
list(range(0,11,2))In [ ]:
list(range(0,101,10))In [ ]:
index_count = 0
for letter in 'abcde':
print("At index {} the letter is {}".format(index_count,letter))
index_count += 1In [ ]:
# Notice the tuple unpacking!
for i,letter in enumerate('abcde'):
print("At index {} the letter is {}".format(i,letter))In [ ]:
list(enumerate('abcde'))In [ ]:
mylist1 = [1,2,3,4,5]
mylist2 = ['a','b','c','d','e']In [ ]:
# This one is also a generator! We will explain this later, but for now let's transform it to a list
zip(mylist1,mylist2)In [ ]:
list(zip(mylist1,mylist2))In [ ]:
for item1, item2 in zip(mylist1,mylist2):
print('For this tuple, first item was {} and second item was {}'.format(item1,item2))In [ ]:
'x' in ['x','y','z']In [ ]:
'x' in [1,2,3]In [ ]:
'x' not in ['x','y','z']In [ ]:
'x' not in [1,2,3]In [ ]:
mylist = [10,20,30,40,100]In [ ]:
min(mylist)In [ ]:
max(mylist)In [ ]:
from random import shuffleIn [ ]:
# This shuffles the list "in-place" meaning it won't return
# anything, instead it will effect the list passed
shuffle(mylist)In [ ]:
mylistIn [ ]:
from random import randintIn [ ]:
# Return random integer in range [a, b], including both end points.
randint(0,100)In [ ]:
# Return random integer in range [a, b], including both end points.
randint(0,100)In [ ]:
input('Enter Something into this box: ')