Learn Python in 10 Lessons: A Crash Course for Beginners
Welcome to DarchumsTech's crash course on Python! Whether you’re looking to break into programming or just curious about Python, this tutorial is your perfect starting point. In just 10 lessons, you'll go from zero to writing functional Python scripts.
Why Python? Python is one of the most popular and beginner-friendly programming languages, used in web development, data science, AI, and automation.
Lesson 1: Hello, World!
Let’s begin by printing your first message.
print("Hello, world!")
Lesson 2: Variables and Data Types
Variables store data. Python has several data types like int
, float
, str
, and bool
.
name = "Alice"
age = 25
height = 5.7
is_student = True
Lesson 3: Basic Input and Output
You can get user input with the input()
function.
name = input("What is your name? ")
print("Hello, " + name + "!")
Lesson 4: Conditional Statements
Use if
, elif
, and else
to control flow.
age = int(input("Enter your age: "))
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
Lesson 5: Loops in Python
Loops help repeat actions. Here’s a for
loop and a while
loop:
for i in range(5):
print(i)
x = 0
while x < 5:
print(x)
x += 1
Lesson 6: Functions
Functions help you reuse code.
def greet(name):
return "Hello, " + name
print(greet("Alice"))
Lesson 7: Lists and Dictionaries
Lists store items in order. Dictionaries store key-value pairs.
fruits = ["apple", "banana", "cherry"]
print(fruits[1]) # banana
person = {"name": "Alice", "age": 25}
print(person["name"])
Lesson 8: Error Handling
Use try
and except
to handle errors.
try:
x = int(input("Enter a number: "))
print(10 / x)
except ZeroDivisionError:
print("Cannot divide by zero!")
except ValueError:
print("Please enter a valid number.")
Lesson 9: File Handling
Read from and write to files easily.
# Write
with open("hello.txt", "w") as file:
file.write("Hello, file!")
# Read
with open("hello.txt", "r") as file:
print(file.read())
Lesson 10: Modules and Your First Project
Python has built-in and external modules. Try creating a mini calculator project:
import math
def calc():
print("Square root calculator")
num = float(input("Enter a number: "))
print("Square root is:", math.sqrt(num))
calc()
Final Thoughts
Congrats! You’ve completed your Python crash course. But this is only the beginning.
- Keep practicing by building small projects.
- Try solving coding problems on platforms like HackerRank, LeetCode, or Replit.
- Stay tuned on DarchumsTech for more tutorials!
Next Up: Learn to build a command-line tool in Python – coming soon!
Subscribe to our newsletter and never miss a Python tutorial.
Comments
Post a Comment