(Home)
101010
from binary to base 10.
2a
from hexidecimal to base 10.
True
if all three are integers, else False
.int
(since a float
can have an integer value).
for
loops, find all Pythagorean triples with hypotenuse < 100.tuple
of length 3 and add it to a list containing all the triples.6 8 10
list
, int
or str
by making a variable with that name (eg, int = 3
- normally you should avoid doing this).
int
value, then change the value of one of the variables and check if it changes the value of the other variable.list
instead of an int
. Modify the the list (change/delete/add an element) and check the values of both variables.
id
built-in method returns a unique integer for every object (try help(id)
) so you can use it to check if variables refer to the same object, or if an operation has modified an existing object or assigned a new object to the same variable.
# Eg:
l = [1,2,3,4,5]
print(l[1:4:1])
[2, 3, 4]
'Brave Sir Robin' => 'nIbOr rIs EvArb'
# Eg:
def arguments(*args) :
print('args =', args)
args
within the function?
# Eg:
def named_args(**kwargs) :
print('kwargs =', kwargs)
# Eg:
named_args()
named_args(a = 1, b = 2)
named_args(t = ('a', 'b', 'c'), l = [1, 2, 3], f = 3.5)
named_args(1, n = 3)
kwargs = {} kwargs = {'a': 1, 'b': 2} kwargs = {'t': ('a', 'b', 'c'), 'l': [1, 2, 3], 'f': 3.5}
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-5a07e324dc60> in <module> 4 named_args(a = 1, b = 2) 5 named_args(t = ('a', 'b', 'c'), l = [1, 2, 3], f = 3.5) ----> 6 named_args(1, n = 3) TypeError: named_args() takes 0 positional arguments but 1 was given
kwargs
within the method?# Eg:
def args_and_keywords(*args, **kwargs) :
print('args =', args)
print('kwargs =', kwargs)
__init__
member function to take values for x, y & z, with their default values being zero.__add__
member function that returns a new 3-vector that's the sum of the vector with another given as an argument, so you can use the +
operator on instances of your class.+
operator on instances of your class.
date
class from the datetime
module to work out how old you are in days.
pickle
to save the date on which you're 10000 days old to a file, then load it again and verify that it's the same date you started with.
(Home)