Welcome to the Python Basics Tutorial! This guide will help you get started with Python, one of the most popular programming languages. Python is known for its simplicity and readability, making it an excellent choice for beginners and experienced programmers alike.

Getting Started

Before you dive into coding, make sure you have Python installed on your computer. You can download the latest version from the official Python website.

Basic Syntax

Python uses indentation to define blocks of code. Here's an example:

print("Hello, World!")

In this example, the print function is used to display the text "Hello, World!" on the screen.

Variables

Variables are used to store data. In Python, you can declare variables without specifying their type:

name = "Alice"
age = 25

Lists

Lists are used to store collections of items:

fruits = ["apple", "banana", "cherry"]

You can access elements in a list using their index:

print(fruits[0])  # Output: apple

Loops

Python supports two types of loops: for and while.

For Loop:

for i in range(5):
    print(i)

While Loop:

count = 0
while count < 5:
    print(count)
    count += 1

Functions

Functions are reusable blocks of code. Here's an example of a simple function that calculates the square of a number:

def square(num):
    return num * num

result = square(4)
print(result)  # Output: 16

Resources

For more information, check out our Python Advanced Tutorial.


Python