Python Basics for Beginners: Tutorials, Cheat Sheets, and Coding Practice
Python is one of the most beginner-friendly programming languages on the planet. Its clean syntax, massive community, and broad use in data science, web dev, and automation make it the ideal first language. This guide covers the fundamentals for new coders—from simple syntax to cheat sheets and job interview prep.
Install Python — Download and Set Up Python on Every Platform
To start coding in Python, you'll first need to install Python. Go to the official download page at https://www.python.org/downloads/ to grab the latest version—currently Python 3.13.5 (released June 11, 2025) (Python Releases for Windows).
Step-by-Step Installation Instructions
✅ Step 1: Download the Installer
Visit python.org/downloads, select your operating system (Windows, macOS, or Linux), and download the installer for Python 3.13.5 (Download Python | Python.org, Python Releases for Windows).
🪟 Step 2: Install on Windows
Run the downloaded .exe installer:
- Check "Add Python to PATH".
- Choose "Install Now" or customize the installation.
- After installation, confirm success:
python --version
Or if that fails:
py --version
🐧 Step 3: macOS / Linux Install
On macOS or Linux:
- Use the installer for your OS.
- Or install via package manager:
sudo apt-get install python3
On macOS you may want to use this Homebrew brew install command to install Python:
brew install python@3.13
NOTE: There's also the macOS installer available on the Python website.
Verify installation:
python3 --version
💻 Step 4: Verify the Version
Make sure you're using the correct version:
python3 --version
# or
py --version # on Windows
📦 Step 5: Use pip for Package Installation
Install Python packages from the official repository using pip, which comes bundled with the installer:
python3 -m pip install requests
# or on Windows
py -m pip install requests
Why Install Python 3.13.5?
Make sure to install the current stable release of Python, as they will be actively maintained with both bug fixes and security updates (Download Python | Python.org, Python Source Releases | Python.org, Python (programming language), Welcome to Python.org). Using the latest version ensures you benefit from improved performance, modern syntax, and long-term support.
By following these steps, you'll have a clean, supported Python installation on any operating system. Once set up, you can run scripts, experiment in shells, and move on to explore modules, projects, and tutorials—all using a robust, up-to-date environment.
Python Run Command: How to Run Python Scripts on Any System
One of the first things beginners need to learn is how to actually run Python code from the command line. The python run command can vary slightly depending on your operating system and how Python is installed.
Running Python Scripts on Different Operating Systems
🐧 Linux and macOS
Most Unix-based systems (including macOS and Linux distros like Ubuntu) use python3 to run scripts, since python often points to Python 2.x:
python3 my_script.py
You can also run Python interactively:
python3
If your system aliases python to Python 3, you can use:
python my_script.py
💡 Tip: Check which version is default with python --version or python3 --version.
🪟 Windows
On Windows, Python installs a launcher called py, which is now the preferred way to run scripts:
py my_script.py
To target a specific version:
py -3.11 my_script.py
Or just open an interactive shell:
py
🧠 Note: If you type python in Command Prompt and it doesn't work, it's likely not added to your PATH. Use py instead.
Using pip Alongside Python
To install Python packages, you'll also need pip, Python's package installer. It usually comes bundled with modern Python installations:
python3 -m pip install requests
Or on Windows:
py -m pip install requests
This installs the requests library for HTTP requests, but the same command works for any package from PyPI.
Summary of Python Run Commands
OS | Script Run Command | Notes |
---|---|---|
Linux/macOS | python3 my_script.py | Use python only if it maps to Python 3 |
Windows | py my_script.py | py is the Python launcher on Windows |
All OS | python3 -m pip install pkg | Use pip to install packages |
Learning how to run Python scripts from the terminal is essential for any developer, especially when working on CLI tools, automation scripts, or deploying apps. Mastering the python run command ensures you're set up to build and execute code smoothly across platforms.
Python Basics for Beginners
If you're just starting out then the following example will give you a good idea how function, conditional logic, and for loops work in Python:
# Variables
name = "Alice"
age = 30
# Conditional logic
if age > 18:
print(f"{name} is an adult")
# Loops
for i in range(5):
print(i)
# Functions
def greet(name):
return f"Hello, {name}!"
These basics form the foundation for writing real Python programs. Practice by building mini projects like a to-do list or calculator.
Python Basics: Cheat Sheet
Here's a quick 'n dirty "cheat sheet" of how you can manipulate and structure your data in Python:
Concept/Type | Example |
---|---|
List | my_list = [1, 2, 3] |
Dictionary | my_dict = {"a": 1} |
Loop | for i in range(10): |
Function | def add(a, b): return a+b |
String Format | f"Hello {name}" |
Grab full PDF cheat sheets from sites like PythonCheatsheet.org or DataCamp's Python Basics PDF.
Python Basics: Code Examples to Practice
Hands-on examples are the best way to learn. Try writing code for:
- A number guessing game
- A temperature converter
- A simple CLI calculator
Python Random Number Example
Here's how you can use Python's built-in random library to generate a random int:
import random
num = random.randint(1, 10)
guess = int(input("Guess a number 1-10: "))
if guess == num:
print("Correct!")
else:
print(f"Wrong! It was {num}")
Python Tutorial for Absolute Beginners
A proper Python tutorial should include:
1. Python installation (via Anaconda or Python.org)
2. Writing scripts in VS Code or PyCharm
3. Running programs from terminal: python myfile.py
4. Understanding syntax, indentation, and debugging
Recommended beginner tutorials:
Python Language Tutorial Overview
Python is a high-level, interpreted language with support for multiple paradigms:
- Imperative: procedural, basic scripts
- Object-Oriented: class, __init__, inheritance
- Functional: map(), filter(), lambda
It's used in:
- Web development (Django, Flask)
- Data science (Pandas, NumPy, Matplotlib)
- Automation (scripts, web scraping)
Python Programming for Beginners Tutorial Walkthrough
Here's a quick outline of what a Python programming tutorial should include:
- Variables, data types, input/output
- If/else logic, while/for loops
- Functions and basic OOP
- Error handling (try/except)
- Modules and importing libraries
- Simple CLI tools (argparse)
Tools you'll want:
- VS Code or PyCharm
- pip or conda for managing packages
- black or flake8 for formatting/linting
Python Basics Interview Questions for Job Seekers
Expect these types of beginner-level questions:
1. What's the difference between a list and a tuple?
2. How does Python handle memory management?
3. Explain the use of *args and **kwargs.
4. What is a dictionary in Python?
5. What are list comprehensions and how are they used?
Example:
# List comprehension
squares = [x**2 for x in range(10)]
Practice by solving problems on platforms like LeetCode, HackerRank, or Codewars.
Python Basics Course Recommendations
If you're serious about learning Python, consider these structured courses:
- CS50's Python Track (Harvard/edX) — Free, academic
- Coursera's Python for Everybody — Taught by Dr. Charles Severance
- Automate the Boring Stuff with Python — Practical scripting use cases
- Codecademy's Python Career Path — Interactive in-browser lessons
Look for a course that includes projects and has an active community or Discord server.
Understanding Python Types and How the type() Function Works
Python has several basic data types that beginners use all the time. These types represent different kinds of values—like numbers, text, or collections. To find out what type something is, you can use the built-in type() function.
Basic Python Data Types Explained
- int — Used for whole numbers.
x = 42
print(type(x)) # <class 'int'>
- float — Used for numbers with decimals.
pi = 3.14
print(type(pi)) # <class 'float'>
- str — A string of text.
name = "Alice"
print(type(name)) # <class 'str'>
- bool — A True or False value.
is_active = True
print(type(is_active)) # <class 'bool'>
- list — An ordered group of values (can be any type).
colors = ["red", "blue", "green"]
print(type(colors)) # <class 'list'>
- tuple — Like a list, but can't be changed.
coords = (4, 5)
print(type(coords)) # <class 'tuple'>
- dict — A group of key-value pairs.
person = {"name": "Bob", "age": 30}
print(type(person)) # <class 'dict'>
- set — An unordered group of unique values.
unique_nums = {1, 2, 3, 3}
print(type(unique_nums)) # <class 'set'>
How to Use type() in Python
The type() function tells you what type a value is:
value = "hello"
print(type(value)) # <class 'str'>
This helps when debugging or writing programs that need to handle different types in different ways.
You can also combine type() with if statements:
if type(value) == str:
print("That's a string!")
This foundational knowledge makes it easier to understand Python code and avoid common type-related errors.
Python is dynamically typed, but understanding its core data types—and how to use them properly—is key to writing reliable code. Whether you're new to the dict or list types, or you're exploring advanced concepts like TypeVar or ctypes.
Common Python Data Types
- int: Whole numbers
- float: Decimal numbers
- str: Text (strings)
- bool: Boolean values (True, False)
- list: Ordered, mutable sequences
- tuple: Ordered, immutable sequences
- dict: Key-value pairs (Python equivalent to an object-literal)
- set: Unordered collections of unique elements
Python List Type Example:
To make a list in Python (often called an "array" in other languages, like JavaScript) you just declare a variable with square brackets:
my_list = [1, 2, 3, "four"]
print(type(my_list)) # <class 'list'>
Python Dict Type Example:
Likewise, just use curly braces for dict Python data:
# It's his birthday. Don't question it.
my_dict = {"name": "Rich Evans", "age": 80, "phrase": "Dict the Birthday Boy!"}
print(type(my_dict)) # <class 'dict'>
🧠 Note on Python dict Keys vs JavaScript Object Keys
In Python, keys must be defined explicitly—typically as strings in quotes:
my_dict = {"name": "Rich Evans"} # ✅ valid
In contrast, JavaScript allows this shorthand without quotes:
const obj = { name: "Rich Evans" } // ✅ valid in JS, but not Python
If you omit quotes in Python, you'll get a NameError unless the key is a variable already in scope:
# ❌ This will break unless name is a defined variable
bad_dict = {name: "Rich Evans"}
Python Type Function and Type Checking
To check the type of a variable, use the built-in type() function:
x = 3.14
print(type(x)) # <class 'float'>
To enforce or validate types, use isinstance():
if isinstance(x, float):
print("x is a float")
You can also use Python's typing module for static type hints:
def add(a: int, b: int) -> int:
return a + b
Python For Loop Types
You can iterate over many different types:
- Lists
- Tuples
- Dictionaries (keys, values, or items)
- Strings
# Python for loop with dict
for key, value in my_dict.items():
print(f"{key}: {value}")
Understanding the type of iterable helps you structure loops correctly.
Python Functions Types and TypeVar
Functions in Python can return or accept multiple types. With the typing module, you can specify return and argument types:
from typing import Union
def stringify(x: Union[int, float]) -> str:
return str(x)
Use TypeVar to define generic functions:
from typing import TypeVar, List
T = TypeVar('T')
def first_item(items: List[T]) -> T:
return items[0]
This enables safer, reusable code in generic functions.
Python CTypes for Low-Level Type Interfacing
For systems programming or interfacing with C libraries, Python's ctypes module allows defining C-compatible types:
import ctypes
x = ctypes.c_int(42)
print(x.value) # Outputs: 42
This is used in advanced scenarios, like interacting with shared libraries (.dll, .so) or writing Python extensions.
Conclusion
Python is an excellent first language for beginners and remains useful even at advanced levels. Whether you're studying cheat sheets, preparing for interviews, or building your first project, the key is consistent practice. Use tutorials, build small tools, and stay curious—Python rewards builders.