CSC108H5 Lecture Notes - Lecture 12: Operand

47 views2 pages
School
Course
897wjface and 39475 others unlocked
CSC108H5 Full Course Notes
12
CSC108H5 Full Course Notes
Verified Note
12 documents

Document Summary

# this is how i can make a new list. # this list has 3 items (two integers and 1 string) # len(lst) is 3, but there is nothing at index 3 so this gives an error. # i can get the last element like this: # a for loop can be used; now, item will equal first element in list, then second, then third. File "", line 2, in print(item + 3) Typeerror: must be str, not int print(item + 3) print(item, 3) print(item + "3") # why? because last item is a string. # notice difference between + and , inside print. # what would happen here? error right away because can"t add 1 to "3" (int to string) # once an error occurs, python quits, nothing else gets executed. File "", line 2, in print(item + "3") Typeerror: unsupported operand type(s) for +: "int" and "str"

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
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions