← Back to Chapters

IDE Setup & Running Python

?️ IDE Setup & Running Python

⚡ Quick Overview

Before writing Python programs, you must have Python installed on your system. Once installed, you can write and run Python code using two common modes:

  • Interactive Mode: Type code directly into the terminal and get instant output.
  • Script Mode: Write code in a .py file and run it later as a full program.

? Key Concepts

  • Use your terminal or command prompt to check if Python is installed with python --version.
  • Interactive Mode is useful for quick testing and learning.
  • Script Mode is best for complete programs saved in files.
  • A Python script file uses the .py extension, for example main.py.

? Syntax and Theory

In interactive mode, you type Python code directly into the Python shell and see the result immediately. This is great for experimenting with small pieces of code.

In script mode, you write your code inside a .py file. This allows you to build larger programs that can be reused, modified, and shared.

? Code Examples

? View Version Check Command
python --version
? View Sample Version Output
Python 3.12.0
? View Interactive Mode Example
>> print("Hello from Python")
Hello from Python
? View Script Mode Example
# main.py
print("This is a Python script")
▶️ View Command to Run Script
python main.py

? Live Output / Explanation

? What You Will See

When you run the version command in your terminal:

python --version

you will see output similar to:

Python 3.12.0

In interactive mode, after typing:

print("Hello from Python")

the shell immediately shows:

Hello from Python

In script mode, running python main.py executes all the code inside main.py and prints:

This is a Python script

? Tips & Best Practices

  • Install python3 instead of python on Linux/Mac if the system already uses Python 2.x.
  • Use an IDE like VS Code or PyCharm to make coding easier.
  • Use interactive mode when you want to quickly test a line or two of code.
  • Use script mode for real projects, automation scripts, and larger programs.

? Try It Yourself

  • Open your terminal and run python.
  • Type: print("Python is fun!")
  • Create a file named hello.py with your own greeting message and run it.
  • Write a small script using a variable and print its value.