ECS 32A Lecture Notes - Lecture 8: Round Number, Tuple

57 views2 pages
24 Jan 2019
School
Course
Professor
1/23/19
Exam Info
40 minutes
1 cheat sheet allowed
True-false, short answer, circle the right answer
Dictionaries: Syntax
Fruit = {}
Fruit = {“apple”: 1.29, “Orange”: 0.79}
Apple and Orange are keys
1.29 and 0.79 are values
Every key is unique to a value
Dictionaries can be advantageous to lists because they keys can have meaningful
names instead of arbitrary integer indices
Properties of Dictionaries
Mutable
You can change the values associated with a key
Values can be of any data type
This is a mapping
from a key space to a value space
Keys must be unique, value may not
Dictionary of Dictionaries
The easiest way to store 2-dimensional data:
Student = [Name’: Nate’, SID’:1234}
Students = {}
Students[Student[Student ID’]] = student
print(students[1234])
Data Types Summary
Numeric
Int: Round Numbers
Float: Numbers with a decimal
Sequence
String: Any text
List: Mutable
Tuple: Immutable
Mapping
Dict: If there is a possibility of expanding your data set
Type Conversions
Called type casting” or casting” in other languages
Implicit conversions
X = 4.0 + 3
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
1 Booster Class
Class+
$8 USD/m
Billed $96 USD annually
Homework Help
Class Notes
Textbook Notes
30 Verified Answers
Study Guides
1 Booster Class