Python, Hello World and the Two Execution Modes
Quick answer What Python is and why it reads the way it does, the first program, and the real difference between typing code at the >>> prompt and saving it in a .py file.
Python was created by Guido van Rossum and first released in 1991. The name comes from the British comedy show Monty Python's Flying Circus, not from the snake. Python 3 arrived in 2008 and deliberately broke compatibility with Python 2 — that is why print needs brackets in every modern book, and why old code you find online sometimes refuses to run. CBSE 083 uses Python 3. Every output on this page was produced by Python 3.13.3.
Features of Python
- Simple and readable. The syntax was designed so that correct code looks close to an English description of what it does.
- Free and open source. Download it from python.org, use it for schoolwork or for a company, pay nothing.
- Interpreted. The interpreter reads and executes your program statement by statement. There is no separate compile step producing an
.exe. This has a consequence you will notice on day one: a run-time mistake on line 20 is only reported after lines 1 to 19 have already run and printed their output. (A syntax mistake is different — Python checks the grammar of the whole file first, so not even line 1 runs. Both cases are demonstrated in the last section.) - Platform independent. The same
.pyfile runs on Windows, Linux, macOS and Android without a change. - Dynamically typed. You never write a type. The type belongs to the value, not to the name.
- Large standard library.
math,randomandstatisticsship with the installation. - Indentation is grammar. Other languages use
{ }to mark a block and treat spacing as decoration. Python uses the spacing itself. You cannot write ugly, un-indented Python that still runs. - Case sensitive.
Marks,marksandMARKSare three different names.
The first program. Save this as hello.py and run python hello.py:
print("Hello World")Output:
Hello WorldWORKED EXAMPLE — the two execution modes. Python can be used in two ways, and CBSE asks you to name and distinguish them.
1. Interactive mode (also called the Python shell). You type one line, press Enter, and it runs at once. The prompt is >>>. A real session:
>>> print("Hello World")
Hello World
>>> 2 + 3
5
>>> "Priodemy"
'Priodemy'
>>> x = 25
>>> x * 4
100Three things to notice. The shell printed 5 and 100 even though there was no print() — interactive mode automatically displays the value of any expression you type. It printed 'Priodemy' with quotes, because it shows you the machine's view of the object, not the human-facing text. And x = 25 printed nothing, because an assignment is a statement, not an expression — it has no value to show.
2. Script mode. The same lines saved in a file demo.py:
# demo.py - script mode
2 + 3
"Priodemy"
print(2 + 3)
print("Priodemy")Real output of python demo.py:
5
PriodemyThe bare 2 + 3 and "Priodemy" were computed and thrown away silently. In script mode nothing appears on screen unless you call print(). This single fact explains most "my program runs but shows nothing" complaints. Note also that print("Priodemy") gave Priodemy without quotes, unlike the shell.
Use interactive mode to test one idea — "what does 17 % 5 give?". Use script mode for anything you want to keep, re-run or submit, because interactive work vanishes when you close the window.
Python character set. The characters Python understands in source code: letters A-Z a-z, digits 0-9, special symbols such as + - * / % = < > ( ) [ ] { } , : . ' " # _ \ @ & | ! ~ ^ ;, and whitespace (space, tab, newline). Python 3 source files are UTF-8 by default, so a string may hold any script in the world, and the interpreter will even accept an identifier written in Devanagari or Tamil. Data in Indian languages is therefore no problem at all:
naam = "Rohit"
print(naam, 500)Rohit 500Legal is not the same as sensible: keep identifiers in English so your code opens correctly on any machine and any examiner can read it.
Case sensitivity, proved:
Marks = 90
marks = 45
print(Marks, marks)
print(Marks == marks)90 45
FalseWORKED EXAMPLE — comments. A comment is text Python ignores. It starts at # and runs to the end of that line. Python has no /* ... */ block comment.
# fees.py : prints the fee slip for one student
# Author: Ananya, Class XI-A
name = "Ananya Sharma" # student name
tuition = 12000 # rupees per term
lab = 1500 # lab fee
"""
This triple-quoted string is not attached to anything,
so Python builds it and throws it away. Students often
use it as a multi-line comment.
"""
total = tuition + lab
print("Student:", name)
print("Total fee: Rs", total)Student: Ananya Sharma
Total fee: Rs 13500The triple-quoted block is not a comment — it is a real string object that gets created and discarded. It works in practice, but if an exam asks "how does Python mark a comment?", the answer is #.
Long statements. A statement normally ends at the end of the line. To spread one over several lines, use a single backslash as the very last character of the line, or better, use brackets:
total = 1200 + \
800 + \
450
print(total)
subjects = ["Physics",
"Chemistry",
"CS"]
print(subjects)2450
['Physics', 'Chemistry', 'CS']Prefer the bracket form. A single invisible space after a backslash breaks the program with SyntaxError: unexpected character after line continuation character, and nothing on screen tells you that the culprit is a space you cannot see.
- Python is interpreted, dynamically typed, case sensitive, free and platform independent; indentation is part of its grammar, not decoration.
- Interactive mode (>>>) echoes the value of every expression automatically; script mode prints absolutely nothing unless you call print().
- Interactive mode shows strings with quotes ('Priodemy'); print() shows them without.
- A comment starts at # and ends with the line. Python has no block-comment syntax; a triple-quoted string used as one is really a string object.
- Source is UTF-8, so strings (and even identifiers) may use any script, but keep names in English for portability and readability.
