🐍beginner
Python Basics — Your First Script
Learn Python fundamentals — variables, types, loops, and functions. The most beginner-friendly programming language.
Why Python?
Python is one of the most popular programming languages in the world. It's used for web development, data science, AI, automation, and more. It's also the most beginner-friendly language because it reads almost like English.
If JavaScript is the language of the web, Python is the language of everything else.
Variables & Types
python
# Variables — no need to declare types
name = "Ishaan"
age = 14
height = 5.6
is_student = True
hobbies = ["coding", "gaming", "reading"]
# Print to console
print(f"Hi, I'm {name} and I'm {age} years old!")
# Type checking
print(type(name)) # <class 'str'>
print(type(age)) # <class 'int'>
print(type(height)) # <class 'float'>Conditions & Loops
python
# If/else
score = 85
if score >= 90:
print("A grade")
elif score >= 80:
print("B grade")
else:
print("Keep trying!")
# For loop
for i in range(5):
print(f"Count: {i}") # 0, 1, 2, 3, 4
# Loop through a list
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(f"I like {fruit}")
# While loop
count = 0
while count < 3:
print(f"Loop #{count}")
count += 1Functions
python
# Define a function
def greet(name):
return f"Hello, {name}! Welcome to Python."
print(greet("Priya"))
# Function with default value
def power(base, exponent=2):
return base ** exponent
print(power(5)) # 25 (5^2)
print(power(3, 3)) # 27 (3^3)
# List comprehension (Python superpower)
numbers = [1, 2, 3, 4, 5]
squared = [n**2 for n in numbers]
print(squared) # [1, 4, 9, 16, 25]Pro Tip
Python uses indentation (spaces) instead of curly braces {} to define code blocks. This is mandatory — if your indentation is wrong, your code breaks. Use 4 spaces per level (most editors do this automatically).
Try It Yourself
Write a Python function called fizzbuzz(n) that prints numbers from 1 to n, but: for multiples of 3 print 'Fizz', for multiples of 5 print 'Buzz', and for multiples of both print 'FizzBuzz'. This is a classic interview question!
Ready to build?
Put what you learned into practice — pick a project and start coding.
Start Building Free