






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Written for easy 5-mark answer writing • Every topic includes definition, example code, output & exam questions
1.1 Overview of Python 1.2 Installation of Python 1.3 Python IDEs 1.4 Python Syntax 1.5 Variables 1.6 Data Types 1.7 Operators 1.8 Type Conversion 1.9 Input / Output Functions ★ Quick Revision — Short Notes ★ Exam Question Bank
Definition Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum and first released in 1991. It emphasizes code readability with its clean, English-like syntax and the use of significant indentation instead of curly braces.
The language is named after the British comedy show "Monty Python's Flying Circus" — not the snake — because Guido van Rossum wanted a name that was short, unique, and slightly mysterious.
Feature Explanation Easy to Learn & Read Simple, English-like syntax makes it beginner-friendly. Interpreted Language Code is executed line-by-line by an interpreter; no separate compilation step needed. Dynamically Typed No need to declare data type of a variable; type is decided at run-time. Free and Open Source Python can be downloaded, used and distributed freely. Portable / Platform-Independent Same code runs on Windows, Linux, Mac without change. Extensive Standard Library Built-in modules for math, file handling, networking, etc. ("batteries included"). Object-Oriented Supports classes, objects, inheritance, polymorphism, etc. Extensible & Embeddable Can be integrated with C/C++/Java code and embedded into other applications. Large Community Support Huge number of third-party libraries (NumPy, Pandas, Django, TensorFlow, etc.)
Web Development — Django, Flask frameworks Data Science & Machine Learning — NumPy, Pandas, TensorFlow, scikit-learn Automation / Scripting — Automating repetitive tasks Game Development — Pygame Desktop GUI Applications — Tkinter, PyQt Networking & Cybersecurity — Socket programming, penetration testing tools Artificial Intelligence — Most widely used language for AI/ML research
Definition An IDE (Integrated Development Environment) is software that provides a code editor, debugger, and run-environment together, making it easier to write, test and debug programs. IDE Description IDLE Python's own default, lightweight IDE that comes bundled with every Python installation. Good for beginners. PyCharm A powerful, feature-rich IDE by JetBrains with intelligent code completion, debugging tools; popular for large professional projects. VS Code A free, lightweight, highly customizable code editor by Microsoft with Python extensions; extremely popular among developers. Jupyter Notebook Browser-based interactive environment that runs code in cells; ideal for data science, visualization and step-by-step experiments. Google Colab Cloud-based, free Jupyter-like notebook that runs on Google's servers; requires no installation and offers free GPU access. Thonny A simple, beginner-oriented IDE with a built-in variable-view, great for learning how programs execute step by step.
Interactive Mode Script Mode Code is typed and executed one line at a time directly at the >>> prompt. Code is written in a .py file and the whole file is executed at once. Useful for testing small snippets quickly. Used for writing complete programs/projects. Results of each statement are shown immediately. Output is shown only when the file is run, usually all together. # Interactive Mode example (typed directly at the >>> prompt) >>> 5 + 3 # Script Mode example -- saved as hello.py, then run using: python hello.py print("Hello, World!") OUTPUT: 8 Hello, World! Exam Question (5 Marks) Q. What is an IDE? Name and briefly explain any four Python IDEs. Also differentiate between interactive mode and script mode. Answer approach: Definition + any 4 rows from the IDE table + the Interactive vs Script table above.
Syntax refers to the set of rules that define how a Python program must be written so that the interpreter can understand it correctly.
Unlike C, C++ or Java (which use curly braces { }), Python uses indentation (whitespace at the start of a line) to define a block of code. Standard practice is 4 spaces per indentation level. # Correct indentation if 5 > 2: print("Five is greater than two!") OUTPUT: Five is greater than two! # Incorrect indentation -- raises IndentationError if 5 > 2: print("Five is greater than two!") OUTPUT: IndentationError: expected an indented block
Single-line comment: starts with # Multi-line comment: written using triple quotes ''' ... ''' or """ ... """ (technically a string, but used as a comment when not assigned) # This is a single-line comment print("Comments example") # comment after code ''' This is a multi-line comment '''
Python is case-sensitive : Name, name, and NAME are treated as three different identifiers.
# Line continuation using backslash total = 10 + 20 + 30 + 40 # Multiple statements on one line using semicolon a = 5; b = 10; print(a + b) OUTPUT: 15
Unlike C/Java, Python statements do not require a semicolon at the end of each line. Common Mistake Mixing tabs and spaces for indentation in the same block causes a TabError. Always use one consistent method (preferably 4 spaces). Exam Question (5 Marks) Q. Explain the basic syntax rules of Python with respect to indentation, comments and case sensitivity. Support your answer with examples. Answer approach: Cover the 5 numbered points above with one short code example each (indentation example is most important — write it fully).
Definition A variable is a named location in memory used to store a value that can change during program execution. In Python, a variable is created the moment a value is first assigned to it — there is no separate declaration step.
Must start with a letter (a-z, A-Z) or an underscore _ — cannot start with a digit. Can contain letters, digits and underscores only (no spaces or special characters like @ # $ %). Cannot be a Python reserved keyword (e.g. if, for, class). Variable names are case-sensitive (age and Age are different). Should be meaningful (e.g. student_name instead of x) as good practice.
# Simple assignment name = "Riya" age = 20 marks = 89. # Multiple assignment in a single line x, y, z = 1, 2, 3 # Assigning the same value to multiple variables a = b = c = 100 print(name, age, marks, x, y, z, a, b, c) OUTPUT: Riya 20 89.5 1 2 3 100 100 100
Python is dynamically typed — the same variable can be reassigned to hold values of different data types during execution; its type is decided automatically at run-time. value = 10 # value holds an integer print(type(value)) value = "Hello" # now the same variable holds a string print(type(value)) OUTPUT:
Definition Operators are special symbols used to perform operations on variables and values (called operands).
Operator Meaning Example (a=10, b=3) Result
Operator Meaning Example (a=10, b=3) Result == Equal to a == b False != Not equal to a != b True > Greater than a > b True < Less than a < b False >= Greater than or equal a >= b True <= Less than or equal a <= b False
Operator Meaning Example and True if both conditions are true (5>2) and (3>1) → True or True if at least one condition is true (5>2) or (3<1) → True not Reverses the result not(5>2) → False
Operator Example Equivalent To = x = 5 x = 5 += x += 3 x = x + 3 -= x -= 3 x = x - 3 *= x *= 3 x = x * 3 /= x /= 3 x = x / 3 //= x //= 3 x = x // 3 %= x %= 3 x = x % 3 **= x **= 3 x = x ** 3
Operator Meaning & Bitwise AND | Bitwise OR ^ Bitwise XOR ~ Bitwise NOT (complement) << Left Shift >> Right Shift
Operator Meaning Example in True if value found in sequence 'a' in 'apple' → True not in True if value NOT found in sequence 'z' not in 'apple' → True
Operator Meaning is True if both variables point to the same object in memory is not True if both variables do NOT point to the same object
a = 10 b = 3 print("Sum:", a + b) print("Floor Division:", a // b) print("Modulus:", a % b) print("Power:", a ** b) print("Is a greater than b?", a > b) print("Logical AND:", (a>5) and (b<5)) OUTPUT: Sum: 13 Floor Division: 3 Modulus: 1 Power: 1000 Is a greater than b? True Logical AND: True Exam Question (5 Marks) Q. What are operators in Python? Explain arithmetic, relational and logical operators with examples. Answer approach: Definition + the three tables (Arithmetic, Relational, Logical) above with the a=10,b=3 examples.
Definition Type conversion is the process of converting the value of one data type into another data type. Python supports two kinds: Implicit (automatic) and Explicit (manual, done by the programmer). Type Conversion in Python Type Conversion
Implicit Conversion Done automatically by Python (e.g. int → float) Explicit Conversion Done manually using functions int(), float(), str(), etc.
Python automatically converts a smaller/lower data type into a larger/higher data type to avoid data loss. This happens without the programmer's intervention, typically in mixed-type expressions. a = 10 # int b = 5.5 # float c = a + b # int is automatically converted to float print(c) print(type(c)) OUTPUT:
The programmer manually converts one data type to another using built-in functions. Function Purpose int(x) Converts x to an integer float(x) Converts x to a floating-point number
.format() method print("My name is {}".format(name)) % operator (old style) print("My name is %s" % name) name = "Aman" marks = 92. # f-string method (most modern & recommended) print(f"{name} scored {marks} marks") OUTPUT: Aman scored 92.5 marks Flow of an Interactive Program using input() and print() Program starts & reaches input() statement
Program pauses; waits for user to type on keyboard
User presses Enter → value stored as string in variable
(If needed) value type-cast using int()/float()
print() displays the final result Exam Question (5 Marks) Q. Explain the input() and print() functions in Python with examples. How is data type conversion relevant while taking input? Answer approach: Explain print() with sep/end table, then input() noting it always returns a string, with the age+1 example showing why int() conversion is required.
High-level, interpreted, general-purpose language by Guido van Rossum (1991). Features: easy syntax, dynamically typed, free & open source, portable, huge library support, OOP. Used in: web dev, data science, AI/ML, automation, game dev, GUI apps.
Download from python.org → run installer → check "Add Python to PATH" → Install Now. Verify with python --version. Use pip install for external libraries.
IDLE (default), PyCharm, VS Code, Jupyter Notebook, Google Colab, Thonny. Interactive Mode = line-by-line at prompt; Script Mode = run a complete .py file.
Indentation (4 spaces) defines code blocks — no curly braces. Comments: # single-line, ''' ''' multi-line. Case-sensitive; no semicolon needed; backslash \ for line continuation.
Named memory location; created on first assignment (no separate declaration). Naming rules: start with letter/underscore, no spaces/special chars, not a keyword, case-sensitive. Python is dynamically typed — type decided at run-time and can change.
Numeric: int, float, complex, bool. Sequence: str, list, tuple, range. Mapping: dict. Set type: set, frozenset. None type: None. list & dict are mutable; tuple & str are immutable. Use type() to check.
Arithmetic: + - * / // % **. Relational: == != > < >= <=. Logical: and, or, not. Assignment: = += -= *= /= etc. Bitwise: & | ^ ~ << >>. Membership: in, not in. Identity: is, is not.
Implicit: automatic, done by Python (int + float → float). Explicit: manual, using int(), float(), str(), list(), tuple(), bool(). int(4.9) truncates to 4 (does not round).
print() displays output; parameters sep (default space) and end (default newline). input() reads from keyboard, always returns a string — cast with int()/float() when needed. f-strings (f"{var}") are the modern, recommended way to format output.