Python Programming Notes
Part 1: Getting Started with Python Basics
A beginner-friendly guide covering what Python is, how to set it up, and the core building blocks of the
language: variables, data types, operators, and basic input/output.
1. What Is Python?
Python is a high-level, general-purpose programming language created by Guido van Rossum and first
released in 1991. It emphasizes readable, clean syntax, which makes it a popular first language for
beginners as well as a serious tool used in web development, data science, automation, artificial
intelligence, and scientific computing.
Key characteristics of Python:
- Interpreted: code runs line by line, no separate compile step needed
- Dynamically typed: you don't declare variable types explicitly
- Readable syntax: uses indentation instead of curly braces
- Huge standard library and third-party package ecosystem (via pip)
- Cross-platform: runs on Windows, macOS, and Linux
1.1 Installing Python
You can download the latest version of Python from [Link]. During installation on Windows, make
sure to check the box that says "Add Python to PATH." On macOS and Linux, Python 3 is often
preinstalled or available through a package manager (e.g., brew install python3 or apt install python3).
To check your installed version, open a terminal or command prompt and run:
python --version
# or on some systems:
python3 --version
1.2 Running Python Code
There are three common ways to run Python code:
1. Interactive shell (REPL): type "python" in a terminal to get a prompt
where you can type and run code line by line.
2. Script file: write code in a .py file and run it with:
python my_script.py
3. Notebook environments: tools like Jupyter Notebook let you run code
in cells, often used for data analysis and learning.
2. Variables and Assignment
A variable is a name that refers to a value stored in memory. In Python, you create a variable simply by
assigning a value to a name with the equals sign (=). You do not need to declare a type ahead of time.
name = "Alice"
age = 30
height = 5.6
is_student = False
print(name, age, height, is_student)
Python variable names must start with a letter or underscore, can contain letters, digits, and
underscores, and are case-sensitive (age and Age are different variables). By convention, variable
names use lowercase with underscores between words (snake_case), e.g. first_name, total_score.
2.1 Multiple Assignment
Python allows assigning multiple variables in a single line, which is useful for swapping values or
initializing several variables at once.
x, y, z = 1, 2, 3
a = b = c = 0 # all three set to 0
x, y = y, x # swap values of x and y
3. Basic Data Types
Every value in Python has a type. The most common built-in types you'll use constantly are:
int whole numbers e.g. 10, -3, 0
float decimal numbers e.g. 3.14, -0.5
str text (strings) e.g. "hello", 'world'
bool True or False e.g. True, False
NoneType represents "no value" e.g. None
You can check the type of any value using the built-in type() function:
print(type(10)) # <class 'int'>
print(type(3.14)) # <class 'float'>
print(type("hi")) # <class 'str'>
print(type(True)) # <class 'bool'>
3.1 Type Conversion
Python provides built-in functions to convert between types. This is called casting.
int("42") # 42 (string to int)
float("3.5") # 3.5 (string to float)
str(100) # "100" (int to string)
int(3.9) # 3 (float to int, truncates)
bool(0) # False (0 is falsy)
bool(5) # True (nonzero numbers are truthy)
4. Strings
Strings represent text and are created with single quotes, double quotes, or triple quotes (for multi-line
text). Strings are immutable, meaning once created, their contents cannot be changed in place.
greeting = "Hello, world!"
multiline = """This is
a multi-line string."""
# Common string operations
print(len(greeting)) # length: 13
print([Link]()) # HELLO, WORLD!
print([Link]()) # hello, world!
print([Link]("Hello", "Hi"))
print(greeting[0]) # first character: H
print(greeting[:5]) # slicing: Hello
4.1 String Formatting
The most modern and readable way to build strings with variable values is the f-string, introduced in
Python 3.6.
name = "Sam"
score = 95
print(f"{name} scored {score} points!")
print(f"Half of {score} is {score / 2}")
5. Numbers and Operators
Python supports the standard arithmetic operators, plus a few extras that are especially handy.
+ addition 10 + 3 -> 13
- subtraction 10 - 3 -> 7
* multiplication 10 * 3 -> 30
/ division 10 / 3 -> 3.333...
// floor division 10 // 3 -> 3
% modulus (remainder) 10 % 3 -> 1
** exponent 10 ** 3 -> 1000
Comparison operators (==, !=, >, <, >=, <=) return a boolean (True or False), and are used constantly
in conditional logic, which we'll cover in Part 2.
print(5 == 5) # True
print(5 != 3) # True
print(7 > 10) # False
6. Input and Output
The print() function displays output to the console. The input() function pauses the program and waits
for the user to type something, always returning the result as a string.
name = input("What is your name? ")
print(f"Nice to meet you, {name}!")
age = int(input("How old are you? "))
print(f"Next year you'll be {age + 1}.")
Note that input() always returns a string, so if you need a number, you must convert it explicitly with
int() or float(), as shown above.
7. Comments
Comments are notes in your code that Python ignores when running the program. They are essential
for explaining why code does something, especially for future you or other developers reading the
code.
# This is a single-line comment
"""
This is a multi-line comment,
often used as a docstring at the
top of a function or file.
"""
x = 5 # you can also comment at the end of a line
8. Practice Exercises
Try these on your own before moving to Part 2:
1. Create variables for your name, age, and favorite color, then print
a sentence using an f-string that includes all three.
2. Ask the user for two numbers using input() and print their sum,
difference, product, and quotient.
3. Write a program that converts a temperature from Fahrenheit to
Celsius: C = (F - 32) * 5/9
4. Create a string variable containing your full name, then print
just the first 3 characters and the string in all uppercase.
End of Part 1. Continue to Part 2: Control Flow and Functions.