Introduction to Python
Last updated on 2026-02-20 | Edit this page
Overview
Questions
- How can I store information?
- How can I perform actions?
Objectives
- Assign values to variables.
- Run built-in functions.
- Import libraries.
Using Python
In the following episodes, we will learn the fundamental knowledge to read and run the Python programming language. To run Python commands, we will use a Jupyter Notebook, an interactive platform to run code, write text, and see your results, such as plots. Follow the instructions in the Setup page to open a Notebook.
Variables
In Python, you store information in variables, which have a name and an assigned value.
PYTHON
variable_name = "value" # Here we assign the value to the variable name
variable_name # Here we ask to see the value
OUTPUT
'value'
The values can be the result of operations.
OUTPUT
'aLongerValue'
Until now, the data type we have been using is string
(str). We saw that summing strings results in a longer
combined string. If we work with numerical values the result will be the
mathematical one.
OUTPUT
300
OUTPUT
600
We can also perform operations with variables that are already set.
OUTPUT
1000
And if we want to be more efficient, we can assign values to more than one variable in the same line.
OUTPUT
'blue'
OUTPUT
'big'
Built-in functions and libraries
Python has basic functions to carry out specific actions. In Python,
the arguments of the functions go inside parentheses, and different
functions take different kinds and numbers of arguments. The function
len() takes one argument and outputs its length. In the
case of a string, the length is the number of characters.
OUTPUT
12
ERROR
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_55271/3566361226.py in <module>
1 a_number = 300
----> 2 len(a_number)
TypeError: object of type 'int' has no len()
The len() function can give us the number of characters
in a string, but it can not do anything with a number (that is of the
type int, meaning integer).
Here, you can check the built-in functions of the Python language.
For extra functionalities, there are libraries, which are collections of functions and data structures (see the next episode) specialized in a common set of tasks.
Pandas is an indispensable library specialized in working with tabular data. To make it accessible, you need to import it. There are several ways to import libraries.
Import a library while establishing an alias to access the functions using the alias.
Import a library without an alias. You need to access the functions with the complete name of the library.
Import only certain functions from a library. You don’t need to specify a name or alias when calling the function.
Exercise 1(Begginer): Creating variables and using functions
Create three variables with the common name of your favorite bird as the variable name and the scientific name as the value. Use built-in functions to get the length of the scientific name that has the maximum length.
- Variables are Python objects that store information when you assign it to them.
- Python has built-in functions that are always accessible.
- Libraries give you access to more functions.