Python Mastery – From Basics to Brilliance / Introduction to Python

Understanding .py Files & The Python Shell

.py File:

🐍 A .py file is a Python source code file used to write and store Python programs.

✨ It allows you to:

  • πŸ“ Write multiple lines of Python code in one file

  • πŸ’Ύ Save your code permanently for future use

  • ▢️ Run the entire program whenever needed

  • πŸ” Reuse and modify the same code multiple times

  • 🐞 Debug and fix errors more easily in an organized way

  • πŸ—οΈ Build small to large Python applications

πŸ“Œ Unlike the Python Shell, where code runs temporarily line by line, a .py file keeps your code saved and structured.

πŸ› οΈ You can create .py files using editors like VS Code, PyCharm, Sublime Text, or any text editor.


How to Open Python Shell

  1. Open Command Prompt or Terminal

  2. Type: python (windows) or python3 (mac/linux)

If Python starts, you will see:

>>>

This means Python Shell is ready.

Example

>>> 5 + 3
8

>>> print("Hello")
Hello

Multi-line Example

>>> for i in range(3):
...     print(i)

Output:

0
1
2

Exit Python Shell

exit() or quit()


Mode

Use Case

Example

Python Shell

Quick testing, tryouts

print(5 + 3)

.py File

Full applications, scripts

Save as app.py

Example:

  • Just like using a calculator for one-time math is quick (Python shell), but you write equations in a notebook when you want to keep them for later (Python file).