Feedback form: https://docs.google.com/forms/d/1A0rjsJUUBlQTXOpHN0wGglDEG4Mte5DorovPTS_cbsI/viewform?usp=send_form
Read these:
Complete reverse_string and primes challenges in challenge folder.
In [55]:
4 is 2**2
Out[55]:
Try evaluating each of the lines below in your python REPL. What's going on?
a = [1, 2, 3]
b = a
b is a
b == a
b = a[:]
b is a
b == a
If you have a hypothesis about the difference between is and ==, devise some tests you could try out to disprove your hypothesis. Implement them. Were you correct?
In [63]:
# a in range(10)
assert a == 1
30 in range(10)
In [83]:
x = False
y = 0
x/y and x
comparison priority
not has the highest priority and or the lowest, so that A and not B or C is equivalent to (A and (not B)) or C.
Short circuit operators
In [90]:
a = [1, 2, 3]
L = [4, 5, 6]
a[len(a):]
Out[90]:
In [96]:
a[:4] + ['b'] + a[4:]
Out[96]:
In [105]:
str1 = "hello"
str1 = list(str1)
str1.insert(3, 'demo')
str1 = ''.join(str1)
str1
# str1 = "Hello world"
# str1 = str1[:3] + 'llllll' + str1[4:]
# str1
Out[105]:
In [110]:
lst = [1 , 2, 3, 4]
lst.remove(3)
lst
Out[110]:
In [114]:
lst.pop(0)
lst
Out[114]:
In [121]:
lst = [1, 2, 3, 4]
lst.clear()
lst
Out[121]:
In [123]:
lst = [1, 2, 2, 3, 4]
lst.index(2)
Out[123]:
In [126]:
lst.count(1)
Out[126]:
In [143]:
lst = [1, 2, 3]
lst.append(5)
lst
Out[143]:
In [146]:
str1 ='abc'
b = list(str1).append(5)
b
Out[146]:
In [166]:
def %(duh):
""" Append 5 to the end of the list"""
return duh + '5'
In [ ]:
def area(xadsf787adf, asdfjljk4):
return xadsf787adf*asdfjljk4
In [164]:
foo = 7
bar = 10
area(foo, bar)
Out[164]:
In [152]:
str1 = 'asdf'
#string_changer(str1)
Out[152]:
In [188]:
def namer(n, a):
print('My name is {name} and my age is {age}'.format(age=a, name=n))
namer('Richie', 8)
In [ ]:
str1.split()
Split a sentence into a list of words (no whitespace), how would you split on comma or semi-colon?
Read up on how to format strings
In [ ]:
10 * (1/0)
In [ ]:
4 + spam*3
In [ ]:
'2' + 2
Handing exceptions
In [ ]:
while True:
try:
x = int(input("Please enter a number: "))
break
except ValueError:
print("Oops! That was no valid number. Try again...")