DataScience Workbook / 04. Development Environment / 2. Python programming environment(s) / 2.1 Online Console: create simple Python code in a browser


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 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.

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.

03_python-online-console.png

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

PythonAnywhere

2. Click-on the green button: Start running Python online and then Create a Beginner account for free

PythonAnywhere

3. Once registered, take a tour to get a quick overview

PythonAnywhere

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.

Example 1: 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 ''.


NOTE:
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, 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)).


NOTE:
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 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.


NOTE:
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

    Homepage Section Index Previous Next top of page