<< 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.

Slicing

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.

A mutable sequence

According to the Python Language Reference -- 3.2. The standard type hierarchy :

Mutable sequences:

Mutable sequences can be changed after they are created.

There are currently two intrinsic mutable sequence types:

  • Lists - The items of a list are arbitrary Python objects. Lists are formed by placing a comma-separated list of expressions in square brackets. (Note that there are no special cases needed to form lists of length 0 or 1.)
  • Byte Arrays - A bytearray object is a mutable array. They are created by the built-in bytearray() constructor. Aside from being mutable (and hence unhashable), byte arrays otherwise provide the same interface andfunctionality as immutable bytes objects.

This module does not discuss ByteArrays .

A list

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."

Some sample programs

Creating, indexing, and slicing lists

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.

An example list

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.

Questions & Answers

List and explain four factors of production
Vuyo Reply
capital labour entrepreneur natural resources
Thembi
What is supply
Ogodo Reply
when the supply decreases demand also decreases
Thembi
types of demand and the explanation
akin Reply
what is demand
akin Reply
other things remaining same if demend is increases supply is also decrease and if demend is decrease supply is also increases is called the demand
Mian
if the demand increase supply also increases
Thembi
you are wrong this is the law of demand and not the definition
Tarasum
Demand is the willingness of buy and ability to buy in a specific time period in specific place. Mian you are saying law of demand but not in proper way. you have to keep studying more. because its very basic things in Economics.
Hamza
Demand is the price of Quantity goods and services in which consumer's are willing and able to offer at a price in the market over a period of time
Umar
Demand is the quantity of goods and services that the consumer are willing and able to buy at a alternative prices over a given period of time. But mind you demand is quite different from need and want.
Tarasum
Demand can be defined as the graphical representation between price&demand
alkasim
sorry demand is nt a graphical representation between price and quantity demand but instead that is demand curve.
Ebrima
Demand is the willingness and ability of a consumer to buy a quantity of a good over a given period of time assuming all other things remain constant.
Vedaant
what is commercialization?
Doris Reply
How to talk loan for bank?
Alfred Reply
what is the meaning of gpa?
Ritisha Reply
Answer: GPA stands for Grade Point Average. It is a standard way of measuring academic achievement in the U.S. Basically, it goes as follows: Each course is given a certain number of "units" or "credits", depending on the content of the course.
Yusuf
what is small and Microbuisenes
tadesse Reply
What is fiscal policy
Dansofo
Who is the funder of Economic
Dansofo
founder , that is Adam Smith
Daniel
what is model
Daniel Reply
The wealth of Nations
Yusuf Reply
the wealth of nations, is it the first?
Umar
Yes very sure it was released in 1759
Yusuf
thank you Yusuf.
Umar
then when did he died?
Umar
17 July 1790 Born: 16 June 1723, Kirkcaldy, United Kingdom Place of death: Panmure House, Edinburgh, United Kingdom
Yusuf
1790
Yusuf
that's my today questions, thank you Yusuf it's bed time see u after.
Umar
what is fiscal policy
kemigisha Reply
what's mode?
Umar Reply
mode is the highest occurring frequency in a distribution
Bola
mode is the most commonly occurring item in a set of data.
Umar
Please, what is the difference between monopoly and monopsony?
Olaleye Reply
is there monopsony word?
Umar
I have no idea though
Umar
please, in which year Adam smith was born?
Umar
monopsony is when there's only one buyer while monopoly is when there's only one producer.
Bola
who have idea on Banter
Ibrahim
like trade by barter?
Bola
Monopoly is when there's excessively one seller and there is no entry in the market while monopsony is when there is one buyer
kemigisha
Adam smith was born in 1723
Bola
 (uncountable) Good humoured, playful, typically spontaneous conversation. verb (intransitive) To engage in banter or playful conversation. (intransitive) To play or do something amusing. (transitive) To tease mildly.
Umar
which book Adam smith published first? the first book of Adam smith pls.
Umar
wealth on nation, 1776
Daniel
what is market power and how can it affect an economy?
Gab Reply
market power:- where a firm is said to be a price setter.market power benefits the powerful at the expense of others.
Umar
Market power refers to the ability of a firm (or group of firms) to raise and maintain price above the level that would prevail under competition is referred to as market or monopoly power. The exercise of market power leads to reduced output and loss of economic welfare
Kartheek
find information about the national budget
Molahlegi
three branches of economics in which tourism is likely to figure
Makgotso Reply
What are those three branches?
IlRegno
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Itse 1359 introduction to scripting languages: python. OpenStax CNX. Jan 22, 2016 Download for free at https://legacy.cnx.org/content/col11713/1.32
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Itse 1359 introduction to scripting languages: python' conversation and receive update notifications?

Ask