In [1]:
b = 5
b = 6
In [2]:
assert b == 6
In [3]:
# Here's a comment!
b = 5
# Here's another comment! Neither of these comments are evaluated by Python!
# this is my comment
In [4]:
b = 6
print(b)
print(500)
In [5]:
# Integer
i = 1
# String
s = "Hello World"
# Float
f = 55.55
hundred_integer = 100
hundred_string = "hundred"
hundred_float = 100.5
In [6]:
assert hundred_integer == 100
In [1]:
a = type(5)
# The type is assigned to a. When you print the type, it is abbreviated to `str`
print(a)
c = type(10)
print(c)
The variable five contains the integer value 5.
Use the arithmetic operators and the variable five to perform calculations that result in 25. Assign to the variable twenty_five.
Use the arithmetic operators and the variable five to perform calculations that result in -5. Assign to the variable negative_five.
In [2]:
five = 5
twenty_five = five * 5
negative_five = -five
assert twenty_five == 25
assert negative_five == -5
In [4]:
ten = "10"
eight = 8
int_ten = int(ten)
str_eight = str(eight)
In [5]:
assert int_ten == 10
assert str_eight == u"8"
In [6]:
l = []
# Print the type of `l` to confirm it's a list.
print(type(l))
l.append("January")
l.append("February")
l.append("March")
l.append("April")
print(l)
In [11]:
l = ["January", "February", "March", "April"]
m = [0,1,2,3]
years = [_ for _ in range(2010, 2015)]
print(years)
In [12]:
o = [u"Jan", 5., 1., u"uary", 10]
In [13]:
print(o)
In [14]:
int_months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
index_four = int_months[4]
last_value = int_months[-1]
In [15]:
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov"]
second_last = months[-2]
In [18]:
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"]
eight_eleven = months[8:12]
ending_index = len(months)
eight_eleven = months[8:ending_index]
five_nine = months[5:10]
print(months[:5])
In [ ]: