Wednesday, 16 January 2013

Application Menu


Application Menu
The application menu provides an easy and familiar way to present a list
of available operations to the user. After reading this section, you can
start building useful tools with an application menu, which perform tasks
according to the user’s requests.
Python Language Lesson: tuple
A tuple is an immutable list. You can’t add, remove or modify its values
after creating it. Tuples are often used to group related values, such as

coordinates, address lines or ingredients of a recipe. Tuples are defined
in the same way as lists but, instead of square brackets, values are
enclosed in parentheses:
red = (255, 0, 0)
weekdays = ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
family = (("Mary", 38), ("John", 35), ("Josephine", 12))
The first and second lines define simple sequences. The last line
makes a tuple of tuples. The inner tuples contain different types of
value: strings and integers.
You can easily unpack values from tuples back to individual variables.
Here we use the tuples red and family that were created
above:
r, g, b = red
mom, dad, child = family
In this case, the variables r, g and b are integers and mom, dad
and child are two-item tuples. Note that you have to define as
many variables in unpacking as there are items in the corresponding
tuple.
You may refer to individual items in a tuple with indices, as with
lists. In contrast to lists, assignments such as
family[1] = ("Jack", 25)
are not possible since this would modify the tuple.
In some cases you need to convert lists to tuples or tuples to lists. The
former is possible with function tuple() and the latter with function
list(). For example:
print list(red)
puts out a list to your screen:
[255, 0, 0]
Note the square brackets that denote a list.

No comments:

Post a Comment