Free Interactive Python Course

Python Tutorial — Learn Python Step by Step

Key takeaway: Master Python programming from scratch — variables, loops, functions, OOP, file handling, and libraries — with clear human-readable explanations and runnable code examples.

50+ Structured Lessons
Runnable Code Examples
100% Free No Registration
Updated October 2026

Python List

A list is an ordered, mutable collection that can hold items of any type. Lists are the most versatile data structure in Python.

Creating Lists

# Empty list
empty = []
also_empty = list()

# List with values
numbers = [1, 2, 3, 4, 5]
mixed = [1, "hello", 3.14, True, None]
nested = [[1, 2], [3, 4], [5, 6]]

# From other iterables
from_range = list(range(1, 6))    # [1, 2, 3, 4, 5]
from_string = list("Python")      # ["P", "y", "t", "h", "o", "n"]

Accessing and Slicing

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

# Indexing (0-based)
print(fruits[0])     # "apple" (first)
print(fruits[-1])    # "elderberry" (last)
print(fruits[-2])    # "date" (second from end)

# Slicing [start:stop:step]
print(fruits[1:3])    # ["banana", "cherry"]
print(fruits[:3])     # ["apple", "banana", "cherry"]
print(fruits[2:])     # ["cherry", "date", "elderberry"]
print(fruits[::2])    # ["apple", "cherry", "elderberry"]
print(fruits[::-1])   # reversed list

Modifying Lists

nums = [1, 2, 3]

# Add elements
nums.append(4)          # [1, 2, 3, 4] — add to end
nums.insert(0, 0)       # [0, 1, 2, 3, 4] — insert at index
nums.extend([5, 6])     # [0, 1, 2, 3, 4, 5, 6] — add multiple

# Remove elements
nums.pop()              # removes and returns last: 6
nums.pop(0)             # removes and returns index 0: 0
nums.remove(3)          # removes first occurrence of 3
del nums[0]             # delete by index
nums.clear()            # remove all elements

# Modify in place
letters = ["a", "b", "c", "d"]
letters[1] = "B"           # replace single item
letters[1:3] = ["X", "Y"]  # replace slice

Common List Operations

nums = [3, 1, 4, 1, 5, 9, 2, 6]

# Sorting
sorted_nums = sorted(nums)       # returns new sorted list
nums.sort()                       # sorts in place
nums.sort(reverse=True)           # descending

# Sort by custom key
words = ["banana", "pie", "Washington", "book"]
words.sort(key=len)               # sort by length
words.sort(key=str.lower)         # case-insensitive sort

# Other operations
print(len(nums))            # length
print(nums.count(1))        # count occurrences
print(nums.index(5))        # find index of value
print(5 in nums)            # membership check: True
print(sum(nums))            # sum of elements
print(min(nums), max(nums)) # min and max

# Copy (shallow)
copy1 = nums.copy()
copy2 = nums[:]
copy3 = list(nums)

List Comprehension

# [expression for item in iterable if condition]
squares = [x**2 for x in range(10)]
evens = [x for x in range(20) if x % 2 == 0]
upper = [s.upper() for s in ["hello", "world"]]

# Nested comprehension (flatten)
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
flat = [num for row in matrix for num in row]
# [1, 2, 3, 4, 5, 6, 7, 8, 9]
  • Lists are mutable — you can change, add, and remove items after creation.
  • Use append() for single items, extend() for adding multiple items.
  • Slicing creates a new list — it does not modify the original.
  • List comprehensions are faster and more Pythonic than equivalent for loops.
  • Use sorted() to get a new sorted list; use .sort() to sort in place.

Python Programming Tutorial — Learn Python in a practical, step-by-step way. According to the official Python documentation, Python emphasizes code readability and simplicity, making it ideal for beginners.

Related tools: Python Online Compiler | Python Examples | JavaScript Tutorial | Java Tutorial

Python Career & Learning Guide

Python is the world's most popular programming language for beginners, data science, AI/ML, web development, and automation. This tutorial teaches Python step-by-step with clear explanations and runnable code examples in our free Python Compiler.

Why Learn Python in 2026?

  • #1 Most Popular Language: Ranked first on TIOBE, Stack Overflow, and GitHub.
  • AI and Data Science: The primary language for machine learning (TensorFlow, PyTorch, scikit-learn) and data analysis (Pandas, NumPy).
  • Web Development: Django and Flask power scalable backends at companies like Instagram and Spotify.
  • Automation & Scripting: Automate files, emails, web scraping, and data processing in minutes.

Python vs Other Languages

FeaturePythonJavaJavaScriptC++
SyntaxVery clean, readableVerboseModerateComplex
TypingDynamic, strongStatic, strongDynamic, weakStatic, strong
Best ForAI/ML, Data, WebEnterprise, AndroidWeb Frontend/BackendSystems, Games
Learning Time2–4 weeks basics4–6 weeks basics3–4 weeks basics8–12 weeks basics

Frequently Asked Questions

Do I need prior programming experience to learn Python?

No! Python is specifically designed to be beginner-friendly. This tutorial starts from zero and builds up gradually.

Which Python version should I use?

Python 3.10+ is recommended. All examples in this tutorial use Python 3 syntax.

Is this Python tutorial completely free?

Yes, 100% free with no registration or sign-up required. Access all lessons and code examples anytime.