Introduction
Overall, using an online platform for Python programming can be a convenient and accessible way to write and run Python code, especially if you are just starting out with the language or don’t want to install anything on your local computer. This choice provides you with:
- convenience & accessibility, write and run Python code from any device with an internet connection, without the need to install any software (including Python)
- no setup required, you can start writing and running code right away; this can be especially useful if you are just starting out with Python and don’t want to spend time setting up a development environment.
- collaboration, useful even for advanced users, e.g., if you are working on a team or sharing your code with others
Open online Python console
There are many online platforms that allow you to write and run Python code directly in your web browser. Several examples are described in the section of the tutorial. For our hands-on exercise we select the PythonAnywhere ⤴ web platform [by Anaconda], using its basic plan to get started with Python coding for free.
python.org/shell
If you want to start right away without creating any free account, open the Python console online at https://www.python.org/shell/ ⤴ and go straight to Start coding in Python section in this tutorial.
pythonanywhere.com
1. Open a new tab in your browser and paste the URL: https://www.pythonanywhere.com ⤴ (or simply click-on the link)
- You will see the webpage interface, shown on the screenshoot below
- You can watch the one-minute video to learn about the features
2. Click-on the green button: and then for free
3. Once registered, take a tour to get a quick overview
4. Click-on the New console: >>> Python
and select version 3.9
Start coding in Python
Follow hands-on examples to create your first Python code
In this section are a few simple examples of Python code that you can try out.
Printing a message to the console
print("Hello, world!")
This code will print the message “Hello, world!” to the console. It uses a built-in Python function print()
. The argument of this function is a text string enclosed in the single or double quotation marks, ""
or ''
.
The print()
function in Python is used to output or display text or other data to the console or terminal. It is a built-in function that takes one or more arguments (values or variables) and prints them to the console. Multiple variables should be separated by a comma.
Storing and manipulating data in variables
x = 10
y = 5
print(x, y)
This code defines two variables, x
and y
, and assigns them the values 10 and 5, respectively. The current value assigned to the variable can be displayed on the console screen using print()
function with a variable as an argument (e.g., print(x)
).
In Python, a variable is a name that refers to a value stored in the computer’s memory. It is used to store data that can be accessed and manipulated by the program.
The type
of a variable is determined automatically based on the value assigned to it.
To assign a value
to a variable in Python, you simply use the assignment operator =
. For example, x = 10
.
Perform some basic arithmetic operations
z = x + y
print(z)
z = x * y
print(z)
This code uses previously defined variables x
and y
to perform some basic arithmetic operations like summing or multiplying. The result of the calculations is assigned to a new variable z
. It stores the most recent assigned value, which can be previewed using a built-in print()
function.
In Python, you can use variables to assign the result of basic mathematical operations such as summing, multiplying, and so on, by using standard mathematical operators:
+
for addition-
for substraction*
for multiplication/
for division
It is highly recommended to learn more about the basics of programming in Python by working through the hands-on tutorials provided in section 05. Introduction to Programming / Introduction to Python programming of this workbook. These tutorials cover topics such as variables, data types, operators, control flow statements, functions, and more.
Further Reading
Online Notebook: interactive Python on Try-jupyter and Colab (no installation)Local Python setup on your computing machine (installation needed)
Shell & IDLE: Python code in a terminal or simple IDE (beginner)
Text editors: create Python code in terminal text files (intermediate)
Jupyter Lab: create an interactive Python notebook (advanced)
PyCharm: IDE for professional Python developers (professional)
R programming environment(s)
RStudio: integrated environment for R programming
Setting up RStudio
MODULE 05: Introduction to Programming