#2 Installing Python / Python Lessons for Beginners

by Alex
#2 Installing Python / Python Lessons for Beginners

Many PCs and Macs already have Python installed. To check this, search for “Python” or type the following at the command line (cmd.exe):

python --version

To check on Linux or Mac, open a command prompt on Linux or open a terminal on Mac and type:

python3 --version

In case you find that python is not installed on your computer, you can download and install it using the instructions in this section.

Quick Start Python

Python is an interpreted programming language, which means that in development you create Python files (.py) in a text editor and then put those files into a python interpreter to run code. The way to run a python file is similar to the command line:

C:\Users\YourName>python helloworld.py

Where “helloworld.py” is the name of your python file. Let’s create our first Python file, called helloworld.py and write the code in it:

print("Hello, World!")

Save the file. Open your command line, go to the directory where you saved the file, and run it:

C:\path\to\folder>python helloworld.py

As a result, you should get:

Hello, World!

Congratulations, you have written and executed your first Python program.

The Python command line

To test a small amount of code in python, it is sometimes easier and faster not to write code to a file. This is made possible because Python can run as a command line itself. Type the following command at the Windows, Mac, or Linux command prompt:

python or python3

From there, you can write any python code you want, including our welcome example:

C:\Users\\_Your Name_> python
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, World!")

On the command line of which you will see “Hello, World!

>>> hello, world!

When you are done with the python command line, you can simply type the following to exit the python shell:

>>> exit()

Related Posts