How to write and execute Python code in 2022

1 min readFundamentalsGetting StartedFiles
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

To run Python code, you will need to execute the script from your terminal using the Python Interpreter.

python my_python_script.py
How to execute a python script from your terminal

The latest version of the Python interpreter can be installed from the main Python website here.

Python can be written with any text editor out there.

However, the vast majority of natively installed text editors won't be the best solution for you to write code.

There are many great text editors made especially for coding.

Those "made for coding" text editors are called integrated development environments or IDE.

Here is a list of the few that are great for coding in Python as of today:

  1. Visual Studio Code (Free) - Made by Microsoft
  2. Atom (Free) - Made by Google
  3. Sublime Text (Free / Paid)
  4. PyCharm (Free / Paid)

Visual Studio Code is great and the IDE that a lot of beginner falls back to.

Write .py files

What are .py files? It's basically the same thing as .txt files but ends with .py.

It gives the information to your operating system that those files contain Python code and that they can be run by the Python interpreter.

We usually call a .py file a Python script.

Here is an example of Python script

my_name = "james"

print(my_name)
Here is the content of a my_python_script.py

How to execute a Python script

Once we have our Python script ready, we execute it in terminal like so:

python my_python_script.py
How to execute a python script from your terminal

Here you are! You now know how to write Python code and how to execute it.

More on fundamentals

If you want to know more about Python fundamentals without headaches... check out the other articles I wrote by clicking just here:

Fundamentals - The Python You Need
We gathered the only Python essentials that you will probably ever need.
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.