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+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions