CME193: IntroductiontoScientificPython Lecture3: Tuples ...
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
................
................
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
- python programming 2 regular expressions lists
- lists and tuples
- a practical introduction to python programming
- python websitesetup
- 6 189 homework 3 mit opencourseware
- sets and set operations university of pittsburgh
- cme193 introductiontoscientificpython lecture3 tuples
- graphframes an integrated api for mixing graph and
- python cheat sheet april 2021 websitesetup
- working with lists and dictionaries