Python Basics
What is Python?
Python is a high-level, interpreted programming language known for its simplicity and readability. It's widely used in data science, machine learning, web development, and automation. Python is great for beginners because its syntax is clean and easy to understand.
Your First Python Program
Let's start with the classic 'Hello, World!' program. This simple program prints text to the screen.
The print() function is one of the most commonly used functions in Python. It displays output to the console.
Variables - Storing Information
Variables are like labeled boxes where you can store information. You put a value in a box (variable) and give it a name so you can use it later.
Choose descriptive variable names to make your code more readable and maintainable.
Data Types - Different Kinds of Data
Python has several built-in data types that store different kinds of information.
Working with Strings (Text)
Strings are sequences of characters. You can manipulate them in many ways.
f-strings (formatted strings) are the modern and preferred way to format strings in Python.
Numbers and Math Operations
Python can perform all standard mathematical operations.
When you divide with /, the result is always a float. Use // for integer division when you need whole numbers.
User Input - Getting Data from Users
You can ask users for input using the input() function.
Always convert user input to the appropriate type (int, float) when working with numbers.
Comments - Making Your Code Understandable
Comments are notes in your code that Python ignores. They help explain what your code does.
Good comments explain WHY, not WHAT. The code already shows what it does. Comments should explain the reasoning behind your approach.
Basic Input/Output - Summary
Here's a complete example that combines input, processing, and output:
Finished reading? Mark it complete to earn your XP.