CSC108H5 Study Guide - Final Guide: Newline, Dict, Tuple

289 views3 pages
22 Apr 2018
School
Course
897wjface and 39475 others unlocked
CSC108H5 Full Course Notes
12
CSC108H5 Full Course Notes
Verified Note
12 documents

Document Summary

// = floor division (whole number, no decimal) Immutable: e. g. 2, float: number w/ decimals. Immutable: e. g. 2. 0, str: text, includes numbers or symbols. Immutable: e. g. (cid:858)hello(cid:859, list: list of items, denoted by square brackets, mutable, e. g. [(cid:858)apple(cid:859), 31, (cid:858)pea(cid:272)h(cid:859): tuple: similar to list, a number of values separated by commas. Immutable: e. g. (cid:894)(cid:858)apple(cid:859), 31, (cid:858)pea(cid:272)h(cid:859)(cid:895, bool: true or false. You can call on the dict key for its value. >>> grades = {ant102: 85, mat102: 85, csc102: 83} To add a ke(cid:455) a(cid:374)d (cid:448)alue that does(cid:374)(cid:859)t alread(cid:455) e(cid:454)ist, (cid:449)e (cid:272)a(cid:374) do: m(cid:455)_di(cid:272)t[(cid:858)(cid:374)e(cid:449)_ke(cid:455)(cid:859)] = (cid:858)(cid:374)e(cid:449)_(cid:448)alue(cid:859) To change a value of a pre-existing key, do the same, except the new value shall replace the old one: m(cid:455)_di(cid:272)t[(cid:858)(cid:374)e(cid:449)_ke(cid:455)(cid:859)] = (cid:858)e(cid:448)e(cid:374)_(cid:374)e(cid:449)er_(cid:448)alue(cid:859) To remove a key, use del: e. g. del (cid:373)(cid:455)_di(cid:272)t[(cid:858)(cid:374)e(cid:449)_ke(cid:455)(cid:859)] setdefault() takes maximum of two parameters: key - key to be searched in the dictionary.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents