Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours
Summary In this hour, you got a little loopy. You learned how to create a for loop and a while loop. Also, you were introduced t ...
...
Part III: Advanced Python HOUR 8 Using Lists and Tuples HOUR 9 Dictionaries and Sets HOUR 10 Working with Strings HOUR 11 Using ...
Hour 8. Using Lists and Tuples What You’ll Learn in This Hour: Working with tuples and lists Using multidimensional lists Buildi ...
[1, 2, 3, 4] >>> tuple4 = tuple(list1) >>> print(tuple4) (1, 2, 3, 4) >>> As you may have noticed in ...
Besides just retrieving a single data value from a tuple, Python also allows you to retrieve a subset of the data values. If you ...
else: print("It's not there!") It's not there! >>> You can also add the not logical operator with the in comparison ope ...
This is a quick way to find the range of values stored in a tuple! Concatenating Tuples While you can’t change the data elements ...
Click here to view code image >>> list4 = ['Rich', 'Barbara', 'Katie Jane', 'Jessica'] >>> print(list4) ['Rich ...
In a much trickier operation, it’s possible to replace a subset of data values with another list or tuple value. You reference t ...
Adding New Data Values You can add new data values to an existing list by using the append() function, as shown here: >>&g ...
result2 = list1.pop() print("The second item removed is", result2) # add one more data value and see where it goes list1.append( ...
[1, 2, 3, 4, 5, 6] >>> Again, the result is a single list of data values. Other List Functions In addition to the list ...
themselves can be lists! In a multidimensional list, more than one index value is associated with each specific data element con ...
print("One value in the list is", x) One value in the list is 1 One value in the list is 15 One value in the list is 46 One valu ...
Creating Lists by Using List Comprehensions As mentioned earlier this hour, in the “Creating a List” section, there’s a fourth w ...
>>> range1 = range(5) >>> print(range1) range(0, 5) >>> print(range1[2]) 2 >>> for x in rang ...
which provides a separate matrix object and functions to perform matrix math using those objects. Q. Most programming languages ...
Hour 9. Dictionaries and Sets What You’ll Learn in This Hour: What a dictionary is How to populate a dictionary How to obtain in ...
In Listing 9.1, a dictionary called student is created. Then the type function is used on it. You can see that student is a dict ...
«
3
4
5
6
7
8
9
10
11
12
»
Free download pdf