Welcome to the exciting world of Python!
Programming is a way to tell your computer how to perform tasks by giving it specific instructions.
A programming library is a collection of code that someone else has written, that you can then use (so you don't have to reinvent the wheel).
We'll learn more about advnaced AI libraries in Python later in the course. Scikit-Learn and TensorFlow are two of the most popular for programming AI and Machine learning programming.
Now let's jump into some programming!
print("I'm here! I'm coding!")
I'm here! I'm coding!
Basic arithmetic operations are built into the Python langauge. Here are some examples. In particular, note that exponentiation is done with the ** operator.
a = 12
b = 2
print("a + b = ", a + b)
print("a time b = ", a*b)
print("a divided by b = ", a/b)
print("a raised to the power of b = ", a ** b)
a + b = 14 a time b = 24 a divided by b = 6.0 a raised to the power of b = 144
Lists are a versatile way of organizing your data in Python. Here are some examples.
colors = ['red', 'blue', 'green']
print(colors[0])
print(colors[2])
print(len(colors))
red green 3
Here are some other common list methods.
list.pop(index) -- removes and returns the element at the given index.
list.reverse() -- reverses the list in place (does not return it).
colors.append('yellow')
colors.insert(0, 'white')
colors
['white', 'red', 'blue', 'green', 'yellow']
colors.sort()
colors
['blue', 'green', 'red', 'white', 'yellow']
colors.remove('orange')
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-7-8f5c5a0abd98> in <module> ----> 1 colors.remove('orange') ValueError: list.remove(x): x not in list
colors.remove('white')
colors
['blue', 'green', 'red', 'yellow']
colors.pop(8)
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-9-8b4a362877f0> in <module> ----> 1 colors.pop(8) IndexError: pop index out of range
colors.pop(2)
'red'
colors
['blue', 'green', 'yellow']
colors.reverse()
colors
['yellow', 'green', 'blue']