DataScience Workbook / 04. Development Environment / 2. Python programming environment(s) / 2.1 Online Console: create simple Python code in a browser
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 2. Online coding platforms ⤴ of the Python programming environment ⤴ 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.
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.
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: Start running Python online and then Create a Beginner account for free
3. Once registered, take a tour to get a quick overview
4. Click-on the
New console: >>> Python and select version
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.
Example 1: Printing a message to the console:
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,
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.
Example 2: Storing and manipulating data in variables:
x = 10 y = 5 print(x, y)
This code defines two variables,
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.,
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.
Example 3: Perform some basic arithmetic operations:
z = x + y print(z) z = x * y print(z)
This code uses previously defined variables
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
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:
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.
2.2 Online Notebook: interactive Python code on Try-jupyter and Colab (without installation)
2.3 Python Setup on your computing machine (installation needed)