In [1]:
print bin(1024)
print hex(1024)
Problem 2: Round 5.23222 to two decimal places
In [2]:
print round(5.2322, 2)
In [3]:
s = 'hello how are you Mary, are you feeling okay?'
print 'Yup' if s.islower() else 'Nope'
Problem 4: How many times does the letter 'w' show up in the string below?
In [4]:
s = 'twywywtwywbwhsjhwuwshshwuwwwjdjdid'
print s.count('w')
Problem 5: Find the elements in set1 that are not in set2:
In [6]:
set1 = {2,3,1,5,6,8}
set2 = {3,1,7,5,6,8}
print set1.difference(set2) # in set 1 but not set 2
print set2.difference(set1) # in set 2 but not set 1
Problem 6: Find all elements that are in either set:
In [9]:
print set1.union(set2) # all unique elements in either set
print set1.intersection(set2) # all elements in both sets
In [10]:
{x:x**3 for x in range(5)}
Out[10]:
In [27]:
l = [1,2,3,4]
l.reverse() # reverses in place, call the list again to check
l
Out[27]:
Problem 9: Sort the list below
In [28]:
l = [3,4,2,5,1]
l.sort()
l
Out[28]: