Starting with Python
// updated 2025-11-10 08:44
In this article, we will look at:
- how to practice Python
- look at some basic code samples
How to practice
At least 3 popular ways for us to get started with Python:
- Using the W3Schools' sandbox
- Using the Google Colab notebooks
- Installing Python on our local machines
ð Using the W3Schools sandbox
- Go straight to the W3Schools sandbox
- Great for playing around with Python code right away
- No account required but no saving work either!
ð Using the Google Colab notebooks
- Go straight to the Google Colab website
- Great for learning Python and taking rich-text notes on the side
- Requires a Google Drive account but lets us save our work in separate files to keep things organized!
ðŧ Installing Python on the local machine
This Codecademy article should explain in great detail how to install Python for Windows and Macs; installing on the local machine:
- might take some time and mouse clicks to set up
- might prove beneficial in the long-run as it prepares the computer for actual development of Python applications
Installation for Macs (used by this article's author)
- Download Python from https://www.python.org/downloads/macos/
- Run the installer like any desktop app, following the instructions
- After installation, open the Terminal app and run the
python3 --versioncommand; the version number should output to the Terminal
(Optional step to alias the "python3" command to "python")
Since Mac comes with Python version 2, the python command by default refers to python2, but we can make Python version 3 the default by having the python alias refer to python3 by editing a file called .bash_profile:
- run this command in Terminal:
open ~/.bash_profile - add the following to the file:
alias python="python3"
alias pip="pip3"- save the file and now run the
python --versioncommand- we have done this step correctly if it outputs the version number
- we can then use
pythoninstead ofpython3in our Terminal commands!
"Hello, world"
The most basic way to start Python is to print something using the print() method:
# helloworld.py - this is a comment!
print("Hello world!")If saving this file on the local machine, we can call it helloworld.py and then run the following command on the same working folder:
$ python helloworld.pyThe output of "Hello world!" should then print after the Terminal command!
There, we have written our first Python program ð
Another example
Now with something a bit more interesting:
# helloworld2.py - this is a comment
def main():
print('hello world - this prints the stuff in the main function')
secondary_function()
def secondary_function():
print('prints when calling this function from main')
tertiary_function()
def tertiary_function():
print('prints when calling this function from secondary_function')
main()- commenting
- most with programming experience (and without Python experience) might gather that the first line represents a comment (starting with
#to denote its role as a comment)
- most with programming experience (and without Python experience) might gather that the first line represents a comment (starting with
- indentation consistency
- in Python, we must indent consistently to help both the computer and the human parse (or read) the code
- def keyword
- used to define a function
- main function
- when the program runs, it will call this function (unless otherwise specified)
- print function
- when the program runs, it will output the contents inside the brackets