You don't have to know how to farm to be a chef - they work at different levels of abstraction in food production.
In computer science, you build bigger, more complex things by using the building blocks others (or you) have provided.
chef image credit: https://www.flickr.com/photos/nestle/3885866873
We've already used several built-in functions in this class: print(), input(), type(), int(), float(), str()
name = input("Enter your name ")
print("Hello",name)
input("Enter your name ") and print("Hello",name) are function calls
Anything you put in the parentheses, like "Enter your name ", "Hello", and name are arguments which are passed to the function
Functions do/execute/compute something based on the arguments
One of the things that makes Python such a great language is that there are many functions you can use that aren't built in.
They're written by other programmers and made available to you.
In order to use them, you need an import statement.
Something you import this way is called a module.
When running a function from a module, you usually use the dot notation.
import random
print( random.randint(1,100) )
In random.randint(1,100), random is the name of the module and randint is the name of the function we want to use from that module. 1 and 100 are arguments we pass to the function that tell it what range of numbers we want our random number to be in.
import datetime
print( datetime.datetime.now() )
Notice that this uses two dots - in this case, the pattern is modulename.typename.functionname becaise the datetime modules contains many different types, and those types each support different functions.
Different modules are set up to be used in slightly different ways.
How do you know how to use a module?
Find the documentation for it on the web!
from IPython.display import IFrame
IFrame('https://docs.python.org/3/library/datetime.html',width=900,height=450)
from IPython.display import IFrame
IFrame('https://docs.python.org/3/library/random.html',width=900,height=450)
type(datetime)
type(datetime.datetime)
current = datetime.datetime.now()
type(current)