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
Contents
Tuples
Dictionaries
Sets
Strings
Modules
Exercises
3: Tuples, sets, dictionaries and strings
3-2
Tuples
Seemingly similar to lists
>>>
>>>
2
>>>
(2,
3: Tuples, sets, dictionaries and strings
myTuple = (1, 2, 3)
myTuple[1]
myTuple[1:3]
3)
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
print y
3: Tuples, sets, dictionaries and strings
# (1, 2, 3)
# 2
3-5
................
................
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
- how to get keys of python dictionary as list tutorial kart
- ppyytthhoonn ddiiccttiioonnaarryy
- dictionaries store connections between pieces of list comprehensions a
- python tuple define access iterate
- cme193 introductiontoscientificpython lecture3 tuples sets
- beginners python cheat sheet pcc dictionaries anarcho copy
- python dictionary tutorial kart
- chapter 12 dictionary hash tables college of engineering
- dictionary case study gktcs
- chapter 2 lists arrays and dictionaries uc davis