←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Revision

Python Programming · Unit 1 Revision

Quick summary and key points for Unit 1

What is Python? Why Python, History & Key Features

Overview: A student can run the same Python source on another computer with a compatible interpreter and libraries.

What is Python?

  • Python is a high-level, interpreted, dynamically typed, object-oriented, and general-purpose programming language.
  • Compare Printing “Hello World” in C vs Java vs Python: (In C or Java, the same task requires 5–7 lines of boilerplate headers, class declarations, and main() methods!)
  • Why do companies like Google, Netflix, NASA, Instagram, Spotify, and ISRO use Python?
  • 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
  • Simple, Readable & Concise Syntax: Python code reads almost like English pseudocode, which drastically reduces software development and debugging time.
  • High Productivity: A task that takes 50 lines of code in Java or C++ can often be written in just 8–10 lines in Python.
  • Dominance in Data Science, AI & Machine Learning: Python is the undisputed king of Artificial Intelligence, Data Analytics, and Scientific Computing thanks to libraries like…

View diagram · Figure 1.1: Why Python? Top Reasons for Python’s Global Popularity

History of Python

  • Creator (Father of Python): Python was conceived and created by Dutch programmer Guido van Rossum at CWI (Centrum Wiskunde & Informatica) in the…
  • When Did It Start? Guido started implementing Python in December 1989 as a hobby project during his Christmas holidays to succeed the **ABC…
  • Why is it Named “Python”? (Important Viva Question!):
  • 1989: Conception
  • 1991: Python 0.9.0
  • 1994: Python 1.0
  • 2000: Python 2.0
  • 2008: Python 3.0

Core Features of Python (Detailed Breakdown)

  • Your DAVV Unit 1 syllabus explicitly lists 7 core features of Python: *Dynamic, Interpreted, Object-oriented, Embeddable, Extensible, Large…
  • 1. Dynamically Typed Language: In C, C++, or Java (Statically Typed languages), you must declare the data type of a variable before using it (int x = 10;).
  • Python is Dynamically Typed—you never declare data types!
  • 2. Interpreted Language: In C/C++, you must first run a separate compiler to generate an executable .exe file before running your code.
  • Python is an Interpreted Language: when you run python app.py, the Python Interpreter automatically compiles your source code…
  • 3. Object-Oriented (and Multi-Paradigm): Everything in Python—even numbers, strings, functions, and modules—is an Object!
  • Python supports both Procedural (function-based) programming and full Object-Oriented Programming (OOP) with classes, objects,…
  • 4. Embeddable (Putting Python Inside Other Languages): Embeddable means you can put Python code inside a program written in another language (like C, C++, or C#) to provide scripting…

View diagram · Figure 1.2: The 7 Core Features of Python in Your DAVV Syllabus

Python Installation (Windows, Linux, Mac), IDLE & Realtime IDEs

Overview: Try 2 + 3 at the interactive prompt to see a result immediately.

Download & Python Installation Process Across Operating Systems

  • Python is a cross-platform language that can be easily downloaded and installed on Windows, UNIX/Linux, and macOS from the official website:…
  • 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 python3
  • A. Installing Python on Microsoft Windows (Step-by-Step): Step 1 (Download): Open a web browser, go to https://www.python.org/downloads/, and click “Download Python 3.x.x” to download the…
  • Step 2 (Crucial Check — Add to PATH): Double-click the downloaded .exe installer.
  • Step 3 (Install Now): Click “Install Now” and wait for the setup wizard to install the Python Interpreter, Standard Library, pip (Python…
  • Step 4 (Verify Installation): Open Command Prompt (cmd) and type:
  • B. Installing Python on UNIX / Linux (Ubuntu, Debian, Fedora): Most Linux distributions come with Python 3 pre-installed.

View diagram · Figure 1.3: Python Installation Process Across Windows, Linux/UNIX, and macOS

Two Modes of Running Python & Python IDLE

  • What is Python IDLE?: IDLE stands for Integrated Development and Learning Environment (also a tribute to Eric Idle, a cast member of *Monty…
  • IDLE comes bundled automatically with every standard Python installation—no extra download is needed!
  • Key Features of IDLE:
  • Interactive Python Shell (>>>): Executes a single Python command immediately as soon as you press Enter.
  • Multi-Window Script Editor: Allows you to write multi-line .py files with syntax highlighting, auto-indentation, and press **F5 (Run…
  • Built-in Debugger: Supports stepping through code and inspecting local/global variables.
  • Online Python IDLE / Compilers: Websites like Google Colab, Replit, PythonAnywhere, and Programiz Online Python allow students to write and…
  • 1. Interactive Mode (Shell Prompt >>>) Type one command at the >>> prompt and press Enter to see the result immediately

View diagram · Figure 1.4: Interactive Mode vs Script Mode in Python IDLE

Python Realtime IDEs (Detailed Syllabus Overview)

  • An IDE (Integrated Development Environment) is a software suite that combines a **Source Code Editor, Interpreter/Runner, Debugger,…
  • 1. Spyder (Scientific Python Development Environment): Target Audience: Specifically designed for Scientists, Data Analysts, Engineers, and Mathematicians (comes pre-installed with the…
  • Key Features:
  • Features a MATLAB / RStudio-style layout with a powerful Variable Explorer (lets you view and edit DataFrames, NumPy arrays, and…
  • Deep built-in integration with NumPy, SciPy, Pandas, and Matplotlib for inline graph plotting.
  • 2. Jupyter Notebook: Target Audience: The world’s #1 interactive environment for Data Science, Machine Learning, Research, and Classroom Teaching.
  • Key Features:
  • A web-based interactive notebook (.ipynb files) that runs in your browser.

Quick Comparison Summary of Python IDEs

  • 1. IDLE: Python (Built-in)
  • 2. Spyder: Anaconda / Community
  • 3. Jupyter Notebook: Project Jupyter
  • 4. PyCharm: JetBrains
  • 5. Rodeo: Yhat
  • 6. VS Code: Microsoft

Python Data Types, Variables, Numbers & Operators

Overview: The value 7 / 2 is 3.5, while 7 // 2 is 3.

Variables in Python

  • A Variable is a named label (reference) attached to an object stored in memory.
  • No Type Declaration Needed (Dynamic Typing): In Python, a variable is created the moment you first assign a value to it using the = operator!
  • Multiple Assignment in One Line: Python allows you to assign values to multiple variables in a single statement:
  • Rules for Naming Python Identifiers (Variables): Can contain letters (a–z, A–Z), digits (0–9), and underscores (_).
  • Must start with a letter or an underscore (_) never with a digit (1st_num is invalid; num_1 is valid).
  • Case-Sensitive: marks, Marks, and MARKS are three completely different variables.
  • Cannot use reserved Python Keywords (if, else, for, while, def, class, True, False, None, and, or, not).

Built-in Data Types in Python

  • Since everything in Python is an object, data types are actually classes, and variables are instances (objects) of these classes.
  • 1. Numeric Types int (Integers), float (Decimals), complex ( 3 + 4j )
  • 2. Sequence Types str (String), list ( [1, 2] ), tuple ( (1, 2) ), range
  • 3. Mapping Type dict (Dictionary of Key-Value pairs: {“id”: 101} )
  • 4. Set Types set (Mutable unique items: {1, 2, 3} ) & frozenset
  • 5. Boolean Type bool — Holds only True or False (Note capital T and F!)
  • 6. None Type NoneType — Special keyword None representing absence of value

View diagram · Figure 1.5: Classification of Built-in Data Types in Python

Numbers in Python (int, float, complex)

  • Your DAVV Unit 1 syllabus specifically highlights Numbers in Python.
  • 1. Integers (int): Whole numbers (positive, negative, or zero) without any fractional/decimal part.
  • Unlimited Precision in Python! Unlike C or Java (where a 32-bit int overflows above 2 billion), an int in Python 3 has unlimited size—it can be 100…
  • Also supports binary (0b1010), octal (0o12), and hexadecimal (0xFF) literals.
  • 2. Floating-Point Numbers (float): Real numbers containing a decimal point (e.g., pi = 3.14159, temp = -4.5) or written in scientific exponential notation (e or E…
  • 3. Complex Numbers (complex): Python has built-in support for Complex Numbers written in the form a + bj (or a + bJ), where:
  • a is the Real part (z.real)
  • b is the Imaginary part (z.imag), and j represents the square root of -1!

Operators in Python (All 7 Categories)

  • Operators are special symbols used to perform arithmetic, logical, or comparison operations on values and variables.
  • +: Addition
  • -: Subtraction
  • *: Multiplication
  • /: True Division
  • //: Floor (Integer) Division
  • %: Modulus (Remainder)
  • 2. Relational (Comparison) Operators: Compare two values and return a Boolean (True or False):

Comments & Input/Output Operations in Python

Overview: If a student types 19 into input, Python initially stores the characters as a string.

Comments in Python

  • Comments are non-executable explanatory notes written inside source code to make the program easier for humans to understand.
  • 1. Single-Line Comment (#) Starts with the hash symbol # and continues till the end of that line
  • 3. Docstrings (“”“…”“”) Triple-quoted string placed as the first line inside a function/class; accessible via doc
  • 1. Single-Line Comments (#): Any text starting with a hash symbol (#) is treated as a single-line comment.
  • 2. Multi-Line Comments: When you need to write a comment spanning several lines, you can either put # at the start of each line OR enclose the block…
  • 3. Docstrings (Documentation Strings — """ ... """): A Docstring is a special multi-line string literal enclosed in triple quotes (`“”” …
  • Difference between a Comment and a Docstring: Unlike # comments (which are stripped out and ignored by Python), Docstrings are retained at runtime and can be…

View diagram · Figure 1.6: Types of Comments & Documentation Strings in Python

Input Operations in Python (input() Function)

  • To make a program interactive, we need to accept input from the user via the keyboard.
  • Golden Rule of input() in Python: input() ALWAYS returns the user’s input as a String (str)!

Output Operations in Python (print() Function)

  • To display output on the console screen, Python provides the built-in print() function.
  • Two Super-Important Parameters of print(): sep and end: This is a favorite 2-mark and 5-mark question in DAVV BCA exams!
  • sep (Separator Parameter — Default is a single space ' '):
  • end (End Parameter — Default is a newline '\n'):

3 Ways of Formatting Output in Python

  • When displaying variables mixed with text, Python offers three formatting styles (with f-strings being the cleanest modern standard):
  • f-Strings (Formatted String Literals — Python 3.6+) Prefix string with f and put variables directly inside { } : f“Name: {name}, Marks: {marks}”
  • The str.format() Method Uses { } placeholders filled by .format() : “Name: {}, Marks: {}”.format(name, marks)
  • Old C-Style % Operator Uses %s (string), %d (int), %.2f (float): “Name: %s, Marks: %d” % (name, marks)

View diagram · Figure 1.7: Three Ways to Format Output Strings in Python