loader image

Getting Started with Python Class 11 Notes: Computer Science | Comprehensive Guide

Getting Started with Python Class 11 Notes Computer Science  Comprehensive Guide

Welcome to the ultimate step-by-step guide on Getting Started with Python Class 11 Notes: Computer Science Notes! If you have just entered Class 11 and feel intimidated by coding, don’t worry-you are in the right place. In this detailed chapter breakdown, we will cover all core concepts from the Python basics Class 11 NCERT curriculum.

We will start with high-level languages and interpreters, move to fundamental building blocks like Python keywords and identifiers, and explore memory management with mutable and immutable data types in Python.

You will also master arithmetic, relational, and logical Python operators and precedence, understand how Python handles data changes through explicit and implicit type conversion in Python, and learn how to fix bugs using Python debugging runtime errors techniques. By the end of this lesson, you will be writing clean, efficient Python programs with complete confidence!

Table of Contents
  1. 1. Introduction to Programming Languages & Python
    1. What is a Computer Program?
    2. Low-Level vs. High-Level Languages
    3. Translators: Interpreters vs. Compilers
  2. 2. Key Features of Python & Execution Modes (Getting Started with Python Class 11 Notes)
    1. Key Features of Python
    2. Python Execution Modes
  3. 3. Python Keywords and Identifiers (Getting Started with Python Class 11 Notes)
    1. Python Keywords (Python keywords and identifiers)
    2. Identifiers
  4. 4. Variables, Memory Allocation & Python’s Object Model
    1. What is a Variable? (Python basics Class 11 NCERT)
    2. Implicit Declaration (Python basics Class 11 NCERT)
    3. Python’s Object Architecture & id() Function
  5. 5. Comments in Python (Python basics Class 11 NCERT)
    1. Types of Comments
  6. 6. Comprehensive Data Types in Python
    1. 1. Numbers
    2. 2. Sequences
    3. 3. Sets (set)
    4. 4. None (NoneType)
    5. 5. Mappings (dict)
  7. 7. Mutable vs. Immutable Data Types (Getting Started with Python Class 11 Notes)
    1. Mutability Summary Table
  8. 8. Operators in Python (Getting Started with Python Class 11 Notes)
    1. 1. Arithmetic Operators
    2. 2. Relational (Comparison) Operators
    3. 3. Assignment Operators
    4. 4. Logical Operators
    5. 5. Identity Operators
    6. 6. Membership Operators
  9. 9. Expressions and Precedence of Operators
    1. Operator Precedence Hierarchy (Highest to Lowest)
  10. 10. Input and Output Statements (Getting Started with Python Class 11 Notes)
    1. 1. User Input: input() Function
    2. 2. Standard Output: print() Function
  11. 11. Type Conversion (Type Casting) (Python basics Class 11 NCERT)
    1. 1. Explicit Type Conversion
    2. 2. Implicit Type Conversion (Coercion)
  12. 12. Program Errors and Debugging (Python basics Class 11 NCERT)
    1. 1. Syntax Errors
    2. 2. Logical Errors (Semantic Errors)
    3. 3. Runtime Errors
  13. 12. Chapter Summary & Quick Revision Key Points

CBSE | Getting Started with Python Class 11 Notes with Solved Examples

Before we start typing code, we must understand how a computer thinks and processes instructions.

A computer cannot act on its own intuition. It requires precise instructions.

  • Program: An ordered set of instructions executed by a computer to perform a specific task.
  • Programming Language: A formal language used to specify these instructions to the computer.

Computers natively understand only Machine Language (Low-Level Language), consisting entirely of 0s and 1s (binary code). Writing programs in binary is tedious and prone to human error.

To overcome this, High-Level Languages (HLL) like Python, C++, and Java were created. They use English-like words, making code easier to write, read, and maintain.

Translating human source code to Machine code

Since computers cannot execute high-level source code directly, a translator is required:

Translators: Interpreters vs. Compilers, Computer Scince Class 11 notes

Python is one of the most versatile and beginner-friendly languages in the world.

  • Free & Open Source: Available to download without licensing fees from python.org.
  • Interpreted Language: Code is executed line-by-line via the Python Interpreter.
  • Easy Syntax & Readability: Clean structure that reads almost like plain English.
  • Case-Sensitive: Identifier names treat uppercase and lowercase letters differently (e.g., NUMBER and number are distinct variables).
  • Portable & Cross-Platform: Runs seamlessly on Windows, macOS, and Linux.
  • Rich Standard Library: Built-in tools for math, file handling, web development, and data analysis.
  • Indentation-Based: Uses whitespace indentation instead of curly braces {} to define code blocks.

Python programs can be run using two primary modes within the Python Shell/IDLE:

Python Execution Modes class 11 computer science
  • How it works: Open the Python Shell where you see the primary prompt >>>. Type a single command and press Enter for immediate execution.
  • Best for: Quick testing and simple math evaluations.
  • Limitation: Statements are not saved. Once the shell closes, your code is lost.
>>> 15 + 25
40
>>> "Class 11 " + "Computer Science"
'Class 11 Computer Science'
  • How it works: Open a new editor file (File -> New File), write multiple lines of code, save the file with a .py extension (e.g., my_program.py), and run it (Run -> Run Module or press F5).
  • Best for: Writing multi-line algorithms, complete applications, and saving code for future use.
# Script Mode Example: prog1.py
print("Welcome to Class 11 Computer Science!")
print("Learning Python is fun!")

Every programming language has strict vocabulary rules.

Keywords are reserved words that carry special meaning to the Python interpreter. You cannot use reserved keywords as names for variables, functions, or objects.

Python Keywords Class 11 Computer Science

Identifiers are custom names given to variables, functions, classes, or modules.

  1. Must begin with an alphabet (a-z, A-Z) or an underscore _.
  2. Can be followed by alphabets, digits (0-9), or underscores _.
  3. Must NOT start with a digit (e.g., 1stStudent is invalid).
  4. Must NOT be a Python keyword.
  5. Must NOT contain special characters/symbols (!, @, #, $, %, etc.).
  6. Can be of any length.
  • Valid: student_name, marks1, _total, avgScore
  • Invalid: 1stRank (starts with digit), total-marks (contains hyphen), class (reserved keyword), user@id (contains special character)

In Python, variables do not store values directly like traditional physical boxes. Instead, variables act as named references or pointers to objects stored in memory.

# Variable Assignment Syntax
variable_name = value

Unlike C++ or Java, Python does not require explicit data type declarations. A variable is automatically declared and typed the moment you assign a value to it.

student_age = 17       # Automatically created as an integer
student_name = "Amit"  # Automatically created as a string

Every value in Python is treated as an object. Each object is assigned a unique memory address identifier (ID) during its lifetime. We inspect this address using the built-in id() function.

>>> num1 = 300
>>> id(num1)
140294829104
>>> num2 = num1
>>> id(num2)
140294829104
Variable reference sharing in python

When num2 = num1 is executed, Python does not create a duplicate copy of 300 in memory. Instead, it routes num2 to reference the exact same memory address as num1.

If we update num1:

>>> num1 = num1 + 100
>>> id(num1)
140294829890

num1 now points to a completely new object (400) at a new memory address, while num2 continues referencing 300 at address 140294829104.

Comments are notes added to code for explanation and readability. The Python interpreter completely ignores comments during execution.

1. Single-line Comments: Use the hash symbol #.

# Calculate total marks
total = math_score + cs_score # Adding subject scores

2. Multi-line Comments: Use multiple single-line # tags or triple-quoted strings (''' or """).

# This program calculates
# the simple interest for
# a given principal amount.

Data types determine what kind of value a variable holds and what mathematical or logical operations can be performed on it.

Data Types in Python | mutable and immutable data types in Python

Stores numerical values only.

  • Integer (int): Whole numbers without decimals (e.g., -15, 0, 450).
  • Boolean (bool): Subtype of integer consisting of True (non-zero/1) and False (0).
  • Floating-point (float): Real numbers with decimal points or exponential notations (e.g., 3.14159, -0.005, 1.5e3).
  • Complex (complex): Numbers in the form a + bj, where a is real and b is imaginary (e.g., 3 + 4j).
x = 100        # <class 'int'>
y = 45.8       # <class 'float'>
z = 2 + 3j     # <class 'complex'>
is_valid = True # <class 'bool'>

An ordered collection of items where each element is indexed by an integer (starting at index 0).

A. Strings (str)

An immutable collection of characters enclosed in single ('...') or double ("...") quotes.

school = "Kendriya Vidyalaya"

B. Lists (list)

An ordered, mutable sequence of comma-separated items enclosed inside square brackets []. Can store mixed data types.

student_data = [101, "Rohan", 95.5, "Class 11"]

C. Tuples (tuple)

An ordered, immutable sequence of items enclosed inside parentheses (). Once created, items cannot be modified, added, or removed.

months = ("Jan", "Feb", "Mar", "Apr")

An unordered collection of unique elements enclosed inside curly braces {}. Duplicate elements are automatically eliminated.

numbers = {1, 2, 2, 3, 4, 4}
print(numbers) # Output: {1, 2, 3, 4}

A special constant used to signal the absence of a value or null status. It is not equivalent to 0 or False.

result = None

An unordered collection of key-value pairs enclosed in curly braces {} with keys separated from values by colons :.

student = {
    "roll_no": 12,
    "name": "Ananya",
    "grade": "A"
}
print(student["name"]) # Output: Ananya

Understanding mutability is crucial for memory management in Python.

  • Mutable Data Types: Data types whose values can be altered in-place without altering their memory address identifier.
  • Immutable Data Types: Data types whose internal values cannot be modified in-place after creation. Modifying them forces Python to allocate a new memory object.
Mutable vs. Immutable Data Types
Mutability Summary Table | Class 11 Computer Science notes

Operators are specialized symbols used to perform computations on variables and values (operands).

Arithmetic Operators in python class 11 coputer science notes

Used to compare two values, returning either True or False.

Assume x = 10 and y = 20:

Python Relational (Comparison) Operators

Assigns right-hand values to left-hand variables.

Python Assignment Operators

Used to combine conditional statements.

Python Logical Operators Class 11 computer science

Determines if two variables point to the same memory object.

Python Identity operators

Tests whether a sequence contains a specified element.

Python Membership Operators class 11 computer science

An expression is a valid combination of constants, variables, and operators that evaluates to a single value.

1. () –> Parentheses (Groupings)

Parentheses are used to group expressions and dictate the order of evaluation explicitly. Operations within parentheses are performed first, allowing for control over the sequence of operations.

2. ** –> Exponentiation

The exponentiation operator raises a number to the power of another. It has a higher precedence than multiplication and division, ensuring that exponentiation is calculated before these operations.

3. +x, -x, ~x –> Unary Plus, Unary Minus, Bitwise NOT

Unary operators, such as unary plus (indicating a positive value), unary minus (negating a value), and bitwise NOT (inverting bits), are evaluated next. They modify a single operand and are processed before binary operations.

4. *, /, //, % –> Multiplication, Division, Floor Division, Modulus

These operators handle various forms of division and multiplication. They share the same precedence level, meaning they are evaluated from left to right in expressions.

5. +, - –> Addition, Subtraction

Addition and subtraction follow multiplication and division in the hierarchy. Like the previous group, they are evaluated from left to right.

6. <, <=, >, >=, ==, != –> Relational Comparison Operators

These operators are used to compare values. They evaluate to boolean results and are processed after arithmetic operations.

7. =, +=, -=, *=, /=, etc. –> Assignment Operators

Assignment operators assign values to variables. They have lower precedence than comparison operators, meaning that comparisons will be evaluated before assignments.

8. is, is not –> Identity Operators

These operators check whether two references point to the same object in memory. They are evaluated after assignment operators.

9. in, not in –> Membership Operators

Membership operators check for the presence of a value within a collection (like lists or dictionaries). They are evaluated after identity operators.

10. not –> Logical NOT

The logical NOT operator negates a boolean value. It has a higher precedence than logical AND and OR operators.

11. and –> Logical AND

The logical AND operator evaluates to true if both operands are true. It has a lower precedence than NOT but higher than OR.

12. or –> Logical OR

The logical OR operator evaluates to true if at least one operand is true. It has the lowest precedence among the logical operators.

Operator Precedence Hierarchy (Highest to Lowest) class 11 cs

Evaluation Example:

Evaluate 15.0 / 4 + (8 + 3.0) step-by-step:

# Step 1: Solve Parentheses (8 + 3.0) -> 11.0
15.0 / 4 + 11.0

# Step 2: Division takes higher precedence over addition (15.0 / 4) -> 3.75
3.75 + 11.0

# Step 3: Addition
14.75

Programs interact with users by accepting input and returning processed results.

Input and Output Statements
  • Accepts data from the user through the keyboard.
  • CRITICAL NOTE: The input() function always returns user data as a string (str) regardless of what is typed.
user_age = input("Enter your age: ")
# If user inputs 18, user_age holds string '18', NOT integer 18

To use numeric inputs for calculations, wrap input() inside explicit type conversion functions like int() or float():

age = int(input("Enter your age: ")) # Converts input string to integer
marks = float(input("Enter percentage: ")) # Converts input string to float

Outputs evaluated expressions or text to the screen.

print(value1, value2, ..., sep=' ', end='\n')
  • sep (Separator): Defines the character used to separate multiple arguments inside print(). Default is a blank space ' '.
  • end: Defines what character is printed at the very end of the output. Default is a new line character '\n'.
print("Class", 11, "CS", sep="-")
# Output: Class-11-CS

print("Hello", end=" ")
print("World")
# Output: Hello World

Type conversion is the process of changing a variable from one data type to another.

Type conversion in python

Performed manually by the programmer using built-in conversion functions.

Explicit Type Conversion in Python
# Program: Adding two number strings using Explicit Type Casting
num1_str = "25"
num2_str = "45"

total = int(num1_str) + int(num2_str)
print("Sum:", total) # Output: Sum: 70

Handled automatically by the Python interpreter during execution when combining different compatible data types. Python promotes smaller data types to wider data types to prevent data loss (Type Promotion).

int_val = 10      # Integer
float_val = 20.5  # Float

sum_val = int_val + float_val
print(sum_val)        # Output: 30.5
print(type(sum_val))  # Output: <class 'float'>

In this example, Python automatically converts int_val (10) to a float (10.0) before performing addition, ensuring precision is maintained.

Debugging is the systematic process of identifying, tracing, and resolving errors (bugs) in software code.

Types of errors in python program

Occurs when code violates the structural grammar rules of the Python language. The interpreter detects syntax errors before execution starts and halts immediately.

  • Examples: Missing parentheses print "Hello", missing colons after if statements, or unclosed string quotes.
# Invalid Code:
print("Class 11 Computer Science
# SyntaxError: EOL while scanning string literal

Occurs when a program runs without crashing but produces incorrect results due to flaws in logic. The interpreter cannot detect logical errors because the code is syntactically correct.

  • Example: Calculating the average of two numbers without using parentheses.
# Incorrect Logic:
num1 = 10
num2 = 20
average = num1 + num2 / 2  # Evaluates to 10 + 10 = 20.0 (Incorrect!)

# Correct Logic:
average = (num1 + num2) / 2  # Evaluates to (30)/2 = 15.0 (Correct!)

Occurs while the program is actively executing. The syntax is correct, but an unexpected condition causes the interpreter to crash.

  • ZeroDivisionError: Attempting to divide a number by zero.
  • ValueError: Passing an invalid argument type to a function (e.g., converting non-numeric text to an integer: int("apple")).
# Example of ZeroDivisionError:
num1 = 10
num2 = 0
result = num1 / num2  # Runtime Error: ZeroDivisionError: float division by zero

To help you review quickly before exams, here is a summary of the core concepts covered in this chapter:

  • Interpreter vs Compiler: Python uses an interpreter to process code line-by-line, stopping immediately when an error occurs.
  • Execution Modes: Interactive mode (>>>) gives instant execution feedback but does not save code, whereas Script mode saves code in .py files for future execution.
  • Keywords & Identifiers: Keywords are reserved words (case-sensitive). Identifiers are custom names that must start with an alphabet or underscore, never a digit.
  • Memory Model: Variables in Python do not store values directly; they store references (pointers) to memory objects.
  • Data Mutability: Immutable types (int, float, str, tuple) cannot be modified in-place. Mutable types (list, set, dict) can be updated in-place without changing memory IDs.
  • Precedence & Types: Parentheses have the highest operator precedence. Type conversion occurs explicitly (via functions like int(), float(), str()) or implicitly (via type promotion).
  • Error Types: Syntax errors break language rules, logical errors produce incorrect calculations, and runtime errors crash programs during execution.

Leave a Comment