PY

Python Fundamentals

18 lessons

Progress0%
1. Introduction to Python
1What is Python?2Setting Up Python
2. Variables and Data Types
1Variables in Python2Data Types
3. Control Flow
Conditional StatementsLoops
4. Functions
Function Basics
5. Data Structures
Lists Deep DiveTuples & SetsDictionaries & Comprehensions
6. Advanced Functions
Closures & Higher-Order FunctionsDecorators & Lambda
7. Object-Oriented Python
Classes & InstancesInheritance & Dunder Methods
8. Exception Handling
try / except / finallyCustom Exceptions & Context Managers
9. Modules & File I/O
Modules & PackagesFile I/O & JSON
All Tutorials
PythonIntroduction to Python
Lesson 2 of 18 min
Chapter 1 · Lesson 2

Setting Up Python

Setting up Python is straightforward. Here's how to get started:

Installing Python:

  1. Visit python.org and download the latest version
  2. Run the installer (check "Add Python to PATH" on Windows)
  3. Verify installation: python --version

Running Python Code:

Option 1: Interactive Mode (REPL)

  • Open terminal/command prompt
  • Type python or python3
  • Type code directly and see results

Option 2: Script Files

  • Create a file with .py extension
  • Run with: python filename.py

Option 3: IDE/Editor

  • VS Code: Free, popular, great Python extension
  • PyCharm: Full-featured Python IDE
  • Jupyter Notebook: Great for data science

Virtual Environments: Keep project dependencies isolated:

code
python -m venv myenv
source myenv/bin/activate  # Linux/Mac
myenv\Scripts\activate     # Windows

Code Examples

Your First Scriptpython
# hello.py - Your first Python script

# Print a greeting
print("Hello, Python!")

# Get user input
name = input("What's your name? ")
print(f"Nice to meet you, {name}!")

# Basic calculation
age = int(input("What's your age? "))
future_age = age + 10
print(f"In 10 years, you'll be {future_age}!")

# Running this script:
# python hello.py

Save this code as hello.py and run it with 'python hello.py' in your terminal.

Quick Quiz

1. What file extension do Python scripts use?

Was this lesson helpful?

PreviousNext