Python Fundamentals#
đ Data Analysis Using Python đ Python Fundamentals Lesson 002
â Previous ¡ Next ✠¡ â Section ¡ â Hub
Important
⨠AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.
The building blocks#
With the motivation established, this lesson covers the fundamentals of Python â the core building blocks from which every program is made. These basics (values, expressions, statements, and how code runs) are the vocabulary the rest of the section builds on, introduced here in Pythonâs clean syntax.
Values and expressions#
Python works with values â the data a program manipulates:
42 # an integer
3.14 # a float (decimal number)
"hello" # a string (text)
True # a boolean (True or False)
Values combine into expressions that Python evaluates to a result:
2 + 3 # evaluates to 5
"data" + "!" # evaluates to "data!" (string concatenation)
10 > 5 # evaluates to True
An expression is anything Python can compute a value from â the basic unit of doing something with data.
Statements and printing#
A statement is an instruction Python executes. The print function displays a
value, the standard way to see a programâs output:
print("Hello, data analysis!")
print(2 + 3) # displays 5
Programs are sequences of statements executed top to bottom, in order â the âsequence of instructionsâ from the previous lesson made concrete.
Variables: naming values#
A variable stores a value under a name, so it can be reused and changed (a dedicated lesson follows):
sales = 1000
tax_rate = 0.08
total = sales + sales * tax_rate
print(total) # displays 1080.0
Assigning with = binds a name to a value; the name then stands for the value
wherever used. Variables are what let a program hold and manipulate data through
meaningful names rather than raw values.
Pythonâs readability#
A defining feature of Python is indentation as structure â Python uses indentation (spaces at the start of a line) to group code into blocks, where other languages use braces. This enforces the visual clarity that makes Python readable, and it means consistent indentation is not optional style but required syntax. This readability â clean syntax, English-like keywords, meaningful indentation â is much of why Python suits analysts, and why code written in it is comparatively easy to read and maintain.
The caveat#
Pythonâs fundamentals are simple individually but combine into subtle behaviour, and a
few basics trip up beginners. Python is case-sensitive (Sales and sales are
different names); indentation errors (inconsistent spaces) are a common frustration
precisely because indentation is meaningful; and the distinction between values and
the variables naming them matters as programs grow. These are learned by writing and
running code, not by reading about it â which is why the environment for doing so, the
next lessonâs subject, matters. The fundamentals reward practice: type the examples, run
them, and change them to see what happens. The next lesson covers where to do that.
Hint
See also
Source article Adapted (context, re-expressed) in our own words from: https://insightful-data-lab.com/2023/12/06/python-fundamentals/ (insightful-data-lab.com).