COMPSCI 1MD3 Lecture Notes - Lecture 4: Reserved Word, Modulo Operation

67 views4 pages

Document Summary

In python, variables are the names of objects. Variables can contain uppercase and lowercase letters, digits, and underscores. Variables must not start with a digit and must not be a reserved word such as def, if, while, return. Python uses indentation for bracketing of nested statements. Variables used within a function are local to the function def factorial(n): i = 0 f = 1 while i < n: i = i+1 f = f*(i+1) return f. All the expressions on the right are evaluated before the values are simultaneously assigned to variables on the left: x, y = y, x (this swaps the values for x and y) Caution: if you try to do this one at a time, it will not work: x = y y = x (both y and x will be the initial value of x) Any function that needs to be iterated uses a counter variable and an accumulator variable.

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