<< Chapter < Page | Chapter >> Page > |
Then the subscription selects the value in the mapping that corresponds to that key.
In other words, the system looks up the word in the dictionary and returns the value that corresponds to that word.
I will have more to say about mappings in a future module.
I discussed slicing at some length in the earlier module titled Itse1359-1070-Strings Part 2 . I will simply refer you back to that module for the discussion on slicing.
According to the Python Language Reference -- 3.2. The standard type hierarchy :
Mutable sequences can be changed after they are created.
There are currently two intrinsic mutable sequence types:
This module does not discuss ByteArrays .
According to The Python Tutorial -- 3.1.3. Lists :
"Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.
Like strings (and all other built-in sequence type), lists can be indexed and sliced.
All slice operations return a new list containing the requested elements."
A list can be written as a sequence of comma-separated values (items) surrounded by square brackets.
Lists can also be nested within other lists.
List items do not all have to be of the same type.
The Python script shown in Listing 4 creates a simple list containing four elements of different types. The types of the elements are respectively, a float value, an integer , a string , and another integer .
Listing 4 . An example list. |
---|
# Illustrates creating,
# indexing, and slicing lists.#
#-------------------------------theList = [3.14,59,"A string",1024]
print("Print index value 2")print(theList[2])print("Print a short slice")
print(theList[0:3])
print("Print the entire list")print(theList[:100]) |
After creating the list, the program uses a subscription (index) to extract and print the value at index 2 (remember the first item is at index 0) .
Then it uses the slice notation to extract and print two different slices from the list.
The first slice extracts and prints the elements from index 0 through index 2 inclusive. (Remember, the items selected by a slice do not include the index specified by the upper limit value, which is 3 in this case.)
The second slice extracts and prints the entire list. If you don't understand these two slices, go back and review the module titled Itse1359-1070-Strings Part 2 where I discussslicing in detail.
Notification Switch
Would you like to follow the 'Itse 1359 introduction to scripting languages: python' conversation and receive update notifications?