Python basics:
1.1 How to start and end python?
To Start:
On windows:
Cmd -> type “python” or py -> enter
To End:
Ctrl + z -> enter / quit() -> enter
1.2 Modes in Python:
2 Modes:
1. Interactive Mode
2. Script Mode
1. Interactive Mode:
Runs one line at a time.
Good for quick testing and small calculations.
Starts when you type python or python3 in the terminal.
Example:
>>> 5 + 3
This is called Interactive Mode because Python runs each line immediately as you type.
2️. Script Mode:
Used to write full programs in a file (with .py extension).
Runs the entire file at once.
Good for building applications and projects.
To run a script, save it in a file ([Link]) and run:
python [Link]
Example ([Link] file):
name = "Varshini"
print("Hello,", name)
Output:
Hello, Varshini
Summary:
Interactive Mode: For quick testing.
Script Mode: For real projects and large programs.
How to Run a Python Script?
Instead of typing everything in the terminal, you can write code in a file and run it.
1. Create a file [Link] and write:
print("Hello, Python!")
2. Save it and run it in the terminal:
python [Link]
Output:
Hello, Python!