Figure 1.1: Why Python? Top Reasons for Python's Global Popularity
Figure 1.1: Why Python? Top Reasons for Python's Global Popularity
1. Beginner-Friendly Syntax
Reads just like plain English; 3–5× shorter code than Java or C++
2. "Batteries Included"
Massive standard library & 500,000+ third-party packages on PyPI
3. #1 in AI, ML & Data Science
Powers ChatGPT, TensorFlow, PyTorch, NumPy, Pandas & Matplotlib
4. Cross-Platform & Versatile
Used for Web (Django/Flask), Automation, Cyber Security, IoT & Cloud
Explanation
- Readable syntax lets a beginner express a calculation in a few lines.
- Libraries extend the same language to tasks such as data analysis and automation.
Figure 1.2: The 7 Core Features of Python in Your DAVV Syllabus
Figure 1.2: The 7 Core Features of Python in Your DAVV Syllabus
1Dynamically Typed
No need to declare variable data types (
x = 10 automatically becomes int)2Interpreted Language
Executed line-by-line by the Python Virtual Machine (PVM) without manual compilation
3Object-Oriented & Multi-Paradigm
Supports both Procedural and OOP (Classes, Objects, Inheritance, Polymorphism)
4Embeddable
Python code can be embedded inside C, C++, or Java applications to add scripting power
5Extensible
Speed-critical parts can be written in C/C++ and called directly from Python!
6Large Standard Library
Built-in modules for OS, Math, Regex, Threading, Networking, Databases & GUI
7Free and Open Source (FLOSS)
100% free to download, use commercially, view source code, and modify
Explanation
- Python uses indentation to group code and objects carry their types at runtime.
- Its interpreter and standard library support many everyday programming tasks.
Figure 1.3: Python Installation Process Across Windows, Linux/UNIX, and macOS
Figure 1.3: Python Installation Process Across Windows, Linux/UNIX, and macOS
1. Windows OS
Download `.exe` installer from `python.org` → Tick "Add python.exe to PATH" → Click Install Now
2. UNIX / Linux OS
Pre-installed on most distros, or install via Terminal:
sudo apt install python33. Apple macOS
Download `.pkg` universal installer from `python.org` or install via Homebrew:
brew install pythonExplanation
- Install or select a Python interpreter suitable for the operating system.
- Run a short script with that interpreter to confirm the setup.
Figure 1.4: Interactive Mode vs Script Mode in Python IDLE
Figure 1.4: Interactive Mode vs Script Mode in Python IDLE
1. Interactive Mode (Shell Prompt >>>)
- Type one command at the
>>>prompt and press Enter to see the result immediately - Great for testing quick formulas and learning syntax
- Code is not saved permanently once you close the window
2. Script Mode (.py File Editor)
- Write a complete multi-line program and save it on disk with a
.pyextension (e.g.,marks.py) - Run via F5 in IDLE or
python marks.pyin terminal - Code is saved permanently and reusable!
Explanation
- Interactive mode evaluates a command immediately so you can try a small expression.
- Script mode runs saved statements in order and makes the work easy to repeat.
Figure 1.5: Classification of Built-in Data Types in Python
Figure 1.5: Classification of Built-in Data Types in Python
1. Numeric Types
int (Integers), float (Decimals), complex (3 + 4j)2. Sequence Types
str (String), list ([1, 2]), tuple ((1, 2)), range3. Mapping Type
dict (Dictionary of Key-Value pairs: {"id": 101})4. Set Types
set (Mutable unique items: {1, 2, 3}) & frozenset5. Boolean Type
bool — Holds only True or False (Note capital T and F!)6. None Type
NoneType — Special keyword None representing absence of valueExplanation
- Numeric and boolean values support calculations and decisions.
- Sequences, sets and mappings organise collections with different access rules.
Figure 1.6: Types of Comments & Documentation Strings in Python
Figure 1.6: Types of Comments & Documentation Strings in Python
1. Single-Line Comment (#)
Starts with the hash symbol
# and continues till the end of that line2. Multi-Line Comment
Written using consecutive
# on each line or unassigned triple quotes '''...'''3. Docstrings ("""...""")
Triple-quoted string placed as the first line inside a function/class; accessible via
__doc__Explanation
- A hash sign starts a comment outside a string literal.
- A docstring is a string in a specific leading position that documents a module, class or function.
Figure 1.7: Three Ways to Format Output Strings in Python
Figure 1.7: Three Ways to Format Output Strings in Python
Method 1f-Strings (Formatted String Literals — Python 3.6+)
Prefix string with
f and put variables directly inside { }: f"Name: {name}, Marks: {marks}"Method 2The str.format() Method
Uses
{ } placeholders filled by .format(): "Name: {}, Marks: {}".format(name, marks)Method 3Old C-Style % Operator
Uses
%s (string), %d (int), %.2f (float): "Name: %s, Marks: %d" % (name, marks)Explanation
- Formatted string literals insert expressions inside braces and format can fill named or numbered fields.
- Percent formatting uses conversion markers to place values in text.