SQL and Python for Absolute Beginners
Python Basics
Getting Started with Python
Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Created by and first released in 1991, Python's simple, clean syntax makes it a popular choice for beginners and experts alike. It's used everywhere, from web development and data science to scripting and automation.
One of Python's core tenets is readability. This idea is so central that it's formalized in a set of guiding principles called the which you can actually view by typing import this into a Python interpreter.
Setting Up Your Workspace
To start writing Python, you need a place to write and run your code. You have two main options:
1. Local Installation: Download and install Python directly from the official website, python.org. This gives you a full-featured environment on your own machine. You'll typically write code in a text editor or an Integrated Development Environment (IDE) like VS Code or PyCharm.
For our purposes, starting with an online tool is the fastest way to get going.
2. Online Interpreter: Use a web-based tool like Replit or Google Colab. These require no installation and let you write and run Python code directly in your browser, making them perfect for learning and experimenting.
Your First Program
The traditional first program for any new language is one that prints "Hello, World!". In Python, it's just one line. This simplicity is a hallmark of the language.
# This is a comment. The interpreter ignores it.
print("Hello, World!")
Here, print() is a built-in function that outputs text to the console. The text you want to print, called a string, is placed inside the parentheses and enclosed in quotes.
Comments, which start with a hash symbol (#), are used to explain your code. They are ignored by the Python interpreter and are there for human readers.
Variables and Data Types
Variables are used to store data. Think of them as labeled containers. You assign a value to a variable using the equals sign (=).
greeting = "Hello, Python!"
user_age = 25
pi_approx = 3.14
print(greeting)
print(user_age)
Python has several fundamental data types. When you assign a value to a variable, Python automatically determines its type. This is known as and makes the language flexible.
Here are the most common basic types:
| Data Type | Description | Example |
|---|---|---|
int | Integer (whole numbers) | 42, -10 |
float | Floating-point number (decimals) | 3.14, -0.001 |
str | String (sequence of characters) | "Hello", 'Python' |
bool | Boolean (logical value) | True, False |
Basic Arithmetic
Python can be used as a powerful calculator. It supports all the standard arithmetic operators you'd expect.
a = 15
b = 4
# Addition
print(a + b) # Output: 19
# Subtraction
print(a - b) # Output: 11
# Multiplication
print(a * b) # Output: 60
# Division
print(a / b) # Output: 3.75
Beyond the basics, there's also the modulo operator (%), which gives you the remainder of a division. It's incredibly useful for tasks like checking if a number is even or odd.
remainder = 15 % 4
print(remainder) # Output: 3 (because 15 divided by 4 is 3 with a remainder of 3)
even_check = 10 % 2
print(even_check) # Output: 0 (so 10 is an even number)
Who is the creator of the Python programming language?
What is the primary purpose of the # symbol in Python code?
You've now covered the absolute fundamentals. You can create variables, understand the basic data types, and perform simple math. This is the foundation upon which all other Python concepts are built.
