We are now ready to get started coding in Python.
But how do we do that?
What do we use?
Well, bring up a terminal window on your Mac machine.
Here is my terminal window.
My prompt might look a little different but
that's because of the customization that I've used.
This is just a plain, old terminal window.
On the terminal window,
run the python --version command in order to see the current version of
Python that is running on your machine that has been installed.
You can see that it's 3.7.1.
This is the version that we just installed using Anaconda.
If you run the command whereis python, you'll find that there is a version of
Python available under /usr/bin/python.
Now, it's important that you remember that this is not the version of Python
that we're going to use.
This is the Python version that comes built in on your Mac.
So, if we hadn't installed Python using Anaconda,
this is the version of Python that would be running on your machine.
But because we do have Python installed using Anaconda,
when you run which python, you'll see the version of
Python that our machine will use to execute our programs.
This is the Python present under /anaconda3/bin/python.
So, even though we have multiple Pythons installed,
this is the Python that will be used, the one in anaconda3.
Here I am in the home directory of my Mac machine.
I'm going to run an ls command here to see what
directories I have under here.
Now, here is the Projects directory and within the Projects directory,
I've already created this sub-folder called Skillsoft.
And within Skillsoft, I have the SkillsoftBasicPython sub-folder.
This is the sub-folder that I'll use to write code.
This is, of course, up to you.
You can choose any directory or folder on your local machine to get started.
But where do we write our Python code?
We'll use a tool or an IDE,
an Integrated Development Environment called Jupyter Notebooks.
You can learn more about Jupyter Notebooks at jupyter.org.
But basically what it is is a browser-based interactive shell where you can
type in code right within your browser window, execute that code, and
see the results of your execution right there within the browser.
Now this is extremely cool because it gives you fast feedback as to
whether you've made a mistake or not.
Jupyter Notebooks is one of the most popular environments that
Python developers use to write and prototype their code.
Running Jupyter Notebook will run the Jupyter Notebook server
right here within your command prompt.
So, make sure that you don't close this terminal window.
The notebook server that we just ran will automatically open up
a browser window.
Or if it doesn't, you can simply copy
paste this URL into a new browser window and that's what I will do here.
And this brings up the home page for Jupyter Notebooks and
this should bring up a browser window that looks like this.
This is the home page for Jupyter where we'll create what are called
Jupyter Notebooks where we'll write our Python code.
The files that you create using Jupyter Notebooks will be automatically saved
within your current working directory or your current folder.
And they will have the ipynb extension.
Now, these files are referred to either as Jupyter notebooks
or IPython notebooks.
IPython is an older name which is still often used.
In order to create a new notebook,
you need to click on this New menu drop-down to the top right of your screen.
Click on New. This will bring up a menu and
you can select the Python 3 option.
Selecting Python 3 indicates that the notebook will run
on the Python 3 kernel.
So, the code that you write will be interpreted and
executed using the Python 3 kernel.
This will open up a new notebook on a new tab on your browser.
And this notebook will automatically get the name Untitled.
It's extremely easy to change the name and rename this notebook so
that it has a name that is meaningful based on the demo or
the Python code that you're going to write.
Select the current name of this notebook, that is Untitled, click on it, and
this will bring up a little dialog.
And then, you can rename this notebook to be anything.
Let's say you want to call it MyFirstPythonNotebook.
Click on the Rename button and
you'll find that your notebook name has been updated.
You're now ready to get started with code. But how do you code?
Well, this little box that you see here on screen is actually a code cell.
And you type in your code within this little box,
and then, you hit Shift+Enter in order to execute this code.
Shift+Enter is what you hit, both of these keys together,
to execute the command that you've typed into the code cell.
Shift+Enter will execute those commands, print the results on screen, and
it will also create new code cells if needed.
Observe that the command that we've typed in here is not really
a Python command.
Instead, it's a shell command or
something that you would type in on your command prompt.
You can also type in your command prompt
commands within your Jupyter Notebook.
Make sure that you proceed these commands with an exclamation point.
This will tell your notebook that this is not a Python command,
instead it's a shell command.
So, we have !python --version that will print out the current
version of Python that we are using which is Python 3.7.1.