for i in range(5): print(i)
0 1 2 3 4
for i in range(50, 101, 10): print(i)
50 60 70 80 90 100
range(start, end, skip)
for i in range(7,10): print(i)
7 8 9
for i in range(4): print(i)
0 1 2 3
for i in range(0.5,1.0,0.1): print(i)
TypeError: 'float' object cannot be interpreted as an integer. Detailed traceback: File "<string>", line 1, in <module>
cereals = {'Special K': 4, 'Lucky Charms': 7, 'Cheerios': 2, 'Wheaties': 3} cereals.items()
dict_items([('Special K', 4), ('Lucky Charms', 7), ('Cheerios', 2), ('Wheaties', 3)])
cereals = {'Special K': 4, 'Lucky Charms': 7, 'Cheerios': 2, 'Wheaties': 3} for cereal, stock in cereals.items(): print( cereal + " has " + str(stock) + " available")
Special K has 4 available Lucky Charms has 7 available Cheerios has 2 available Wheaties has 3 available
numbers = [2, 3, 5]
squared = list() for number in numbers: squared.append(number ** 2) squared
[4, 9, 25]
squared = [number ** 2 for number in numbers] squared
numbers = [2, 3, 5] word_length = {number : number ** 2 for number in numbers} word_length
{2: 4, 3: 9, 5: 25}