Back to Python

Python Basics

Introduction to Python

Python is a high-level, interpreted programming language known for its simplicity and readability. It's widely used for web development, data analysis, artificial intelligence, and more.

print("Hello, World!")

This simple line demonstrates Python's straightforward syntax for outputting text to the console.

Variables and Data Types

Python is dynamically typed, meaning you don't need to declare variable types explicitly. Common data types include:

# Integer
age = 25
# Float
price = 19.99
# String
name = "Alice"
# Boolean
is_active = True
# List
colors = ["red", "green", "blue"]
# Dictionary
person = {"name": "Bob", "age": 30}

Operators

Python supports various operators for performing operations on variables and values:

Arithmetic

+, -, *, /, %, **, //

Comparison

==, !=, >, <,>=, <=< /p>

Logical

and, or, not

# Arithmetic example
result = 10 + 5 * 2 # result will be 20

# Comparison example
if age >= 18:
    print("Adult")

Control Flow

Python uses indentation to define blocks of code for control structures:

if x > 0:
    print("Positive")
elif x == 0:
    print("Zero")
else:
    print("Negative")

# For loop example
for i in range(5):
    print(i)

# While loop example
count = 0
while count < 5:
    print(count)
    count += 1

Functions

Functions are reusable blocks of code that perform a specific task:

def greet(name):
    return f"Hello, {name}!"

# Call the function
message = greet("Alice")
print(message) # Output: Hello, Alice!

YouTube Learning Resources

Boost your Python skills with these handpicked video resources:

Python Basics Quiz