Python Basics¶
Python is widely used because it is readable, versatile, and supported by a large ecosystem of scientific and general-purpose libraries. In RECODE, we use it as the common language for examples, exercises, and small research tools.
Ways to run Python¶
You will encounter Python in three common forms:
- Interactive terminal for quick experiments,
- scripts for repeatable code stored in
.pyfiles, - notebooks for teaching, exploration, and mixed text/code workflows.
Each one is useful. What matters is recognizing when to use which format.
Variables and names¶
Variables store values so you can reuse them later:
Choose names that describe the meaning of the value, not just its type.
sample_name is better than x, and is_valid is better than flag1.
Core data types¶
Some common Python data types are:
strfor text,intfor whole numbers,floatfor decimal numbers,boolforTrue/False,complexfor complex numbers.
You can inspect a value's type with:
Expressions and operators¶
Python follows standard mathematical rules for many operations:
Parentheses help make intent explicit:
Functions¶
Functions let you name a reusable action:
You can then call the function with different inputs:
Functions are one of the first major steps from "typing commands" to "writing programs."
Basic imports¶
Python's standard library already contains many helpful tools:
External libraries add more capabilities:
This is a common pattern in scientific Python: start with core language features, then bring in specialized libraries when the problem requires them.
Notebooks as a learning tool¶
The introductory notebook in the repository shows a useful teaching pattern:
- write a small code cell,
- run it immediately,
- inspect the result,
- modify one thing and run it again.
That feedback loop is especially effective when learning basics such as:
- printing values,
- checking data types,
- comparing lists and arrays,
- plotting simple results.
Practice ideas¶
Try the following on your own:
- Create three variables with different types.
- Write a function that converts Celsius to Kelvin.
- Import
mathand calculate a square root. - Print a sentence that includes both text and a number.
The point is not complexity. The point is building fluency with the syntax.