Understand Python fundamentals and syntax
Set up VS Code for Python development
Write and execute your first Python programs
Master variables, data types, and operators
Control program flow with if/else and loops
Write reusable functions and understand scope
Download VS Code from code.visualstudio.com and install it for your operating system.
Python - Official Python extension by Microsoft
Pylance - Fast, feature-rich language support
GitHub Copilot - AI pair programmer
Pylint - Code quality checker
Black Formatter - Automatic code formatting
Press Ctrl+Shift+P and search for Python: Select Interpreter to choose your Python installation.
Variables are containers for storing data values. In Python, you create a variable by assigning a value to a name.
name = "Alice"
age = 25
height = 5.7
is_student = True
print(f"Name: {name}")
print(f"Age: {age}")
print(type(name)) # str
print(type(age)) # intscore = 85
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "F"
print(f"Grade: {grade}")def greet(name):
print(f"Hello, {name}!")
greet("Alice")
def add(a, b):
return a + b
result = add(5, 3)
print(result) # 8
def introduce(name, age=25):
print(f"My name is {name} and I am {age}")
introduce("Bob")
introduce("Charlie", 30)Create a program that prompts for two numbers and an operation, performs the calculation, and asks to continue.
def calculator():
while True:
try:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operation = input("Enter operation (+, -, *, /): ")
if operation == "+":
result = num1 + num2
elif operation == "-":
result = num1 - num2
elif operation == "*":
result = num1 * num2
elif operation == "/":
if num2 == 0:
print("Cannot divide by zero")
continue
result = num1 / num2
else:
print("Invalid operation")
continue
print(f"Result: {result}")
again = input("Calculate again? (yes/no): ")
if again.lower() != "yes":
break
except ValueError:
print("Invalid input")
if __name__ == "__main__":
calculator()Use the interactive sandbox below to practice Python fundamentals. Modify the code and click Run Code to see the results.
Edit the code and run it to see Python in action