CME193: IntroductiontoScientificPython Lecture3: Tuples,sets ...
CME 193: Introduction to Scientific Python Lecture 3: Tuples, sets, dictionaries and strings
Sven Schmit
stanford.edu/~schmit/cme193
3: Tuples, sets, dictionaries and strings
3-1
Tuples Dictionaries Sets Strings Modules Exercises
Contents
3: Tuples, sets, dictionaries and strings
3-2
Tuples
Seemingly similar to lists
>>> myTuple = (1, 2, 3) >>> myTuple[1] 2 >>> myTuple[1:3] (2, 3)
3: Tuples, sets, dictionaries and strings
3-3
Tuples are immutable
Unlike lists, we cannot change elements.
>>> myTuple = ([1, 2], [2, 3]) >>> myTuple[0] = [3,4] Traceback (most recent call last):
File "", line 1, in TypeError: 'tuple' object does not support item assignment >>> myTuple[0][1] = 3 >>> myTuple ([1, 3], [2, 3])
3: Tuples, sets, dictionaries and strings
3-4
Packing and unpacking
t = 1, 2, 3 x, y, z = t print t # (1, 2, 3) print y # 2
3: Tuples, sets, dictionaries and strings
3-5
Functions with multiple return values
def simple_function(): return 0, 1, 2
print simple_function() # (0, 1, 2)
3: Tuples, sets, dictionaries and strings
3-6
Tuples Dictionaries Sets Strings Modules Exercises
Contents
3: Tuples, sets, dictionaries and strings
3-7
Dictionaries
A dictionary is a collection of key-value pairs. An example: the keys are all words in the English language, and their corresponding values are the meanings. Lists + Dictionaries = $$$
3: Tuples, sets, dictionaries and strings
3-8
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- chapter 13 tuples
- auto declare array of tuples angry
- more examples using lists tuples and dictionaries in python
- programming with python lists tuples and dictionaries
- tuples open michigan
- data structures in python grapenthin
- python tuples university of babylon
- tuples dr chuck
- cme193 introductiontoscientificpython lecture3 tuples sets
- python data structures cheat sheet intellipaat