Introduction to Python
Introduction to Python
Tuples and Dictionaries
1
Topics
1) Tuples 2) Tuple unpacking 3) List of tuples, List of lists(2D lists) 4) enumerate() 5) Dictionaries 6) Iterating over a dictionary
2
Tuples
Tuples are in many ways similar to lists, but they are defined with parentheses rather than square brackets: t = (1, 2, 3) They can also be defined without any brackets at all: t = 1, 2, 3 print(t, type(t)) # (1, 2, 3) tuple
3
Tuples
Like the lists, tuples have a length and individual elements can be extracted using square-bracket indexing. Slicing is also supported.
t = (1, 2, 3) print(len(t)) print(t[0]) print(t[0:2])
# 3 # 1 # [1, 2]
4
Tuples
Unlike lists, tuples are immutable: this means that once they are created, their size and contents cannot be changed:
lst = [1, 2, 3] lst[1] = 5 t = (1, 2, 3) t[0] = 1 t.append(10)
# ok! a list is mutable
# error! a tuple is immutable # error! a tuple is immutable
Note: a tuple takes less memory than a list and can be generally manipulated faster.
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
- data types in python
- cs116 iterating through all of a list part 1 purpose
- basic python programming for loops and reading files
- cs2304 sequences and collections virginia tech
- python day 3 lists branching iwks
- htseq a python framework to work with high throughput
- python quick revision tour
- compsci 101 principles of programming sequences strings
- data structures lists stack queue
- iterating over lists sequences
Related searches
- introduction to financial management pdf
- introduction to finance
- introduction to philosophy textbook
- introduction to philosophy pdf download
- introduction to philosophy ebook
- introduction to marketing student notes
- introduction to marketing notes
- introduction to information systems pdf
- introduction to business finance pdf
- introduction to finance 15th edition
- introduction to finance books
- introduction to finance online course