COMP10001 Lecture Notes - Lecture 3: Hexadecimal, Local Variable
![](https://new-preview-html.oneclass.com/xBXoz56OAaVyNBo5ZM73Q9n37kpbwJqR/bg1.png)
define variable
-
arity functions by specifying default values for arguments (x=n)
-
function variables are not accessible from outside the function call
○
functions can access variables defined outside
○
each function call defines its own local variable scope
-
Functions:
defined for objects of a given type
-
called as object.method()
-
.upper() = return in all uppercase
○
.lower() = return in all lowercase
○
.strip(string) = return with all instances of characters in string (whitespace if no string)
removed from start and end
○
useful methods
-
Methods:
insert variables into string by indexing relative to the arguments to format
-
.format()
-
f = float
○
d = decimal integer
○
x = hexadecimal (base
-
16) integer
○
o = octal (base
-
8) integer
○
b = binary (base
-
2) integer
○
format specifiers
-
Strings and formatting:
tool to make the computer do something over and over again
-
a = a + 1
for i in "abc":
print(a)
e.g. a = 0
○
for loops
-
range(start, end, step) = generate a sequence of int values from start (inclusive) to end (non
-
inclusive), counting step at a time
-
while loops
-
break ends while loops and bypasses the condition in the while statement
-
Iteration:
use ( , ) to build them
-
used to represent multi
-
variate objects
-
to return multiple values
○
to swap values between variables
○
to test for one of a series of values
○
as keys to dictionaries
○
useful applications
-
immutable (cannot change elements)
-
Tuples:
Week 3
Wednesday, 21 March 2018 10:23 PM
Foundations of Computing Page 1