Home › Free notes › Class 11 Computer Science › Getting Started with Python
Getting Started with Python – Class 11 Computer Science notes, important questions and MCQs
NCERT Class 11 Computer Science, chapter 5. Notes, key terms, important questions with answers and MCQs.
Chapter overview
Python is a high-level, interpreted, free and open source programming language created by Guido van Rossum and released in 1991. It is easy to read, portable and widely used. Python programs can be run in interactive mode or script mode. This chapter covers keywords, identifiers, variables, data types, operators, expressions, input and output, type conversion, and types of errors.
Basics
- Python works in interactive mode (shell, >>> prompt, one statement at a time) and script mode (a .py file run as a whole).
- Keywords are reserved words such as if, else, for, while, def, True and None; identifiers are names for variables and functions that must start with a letter or underscore, cannot be keywords and are case-sensitive.
- Variables refer to objects in memory; Python is dynamically typed. Data types include numbers (int, float, complex), bool, sequences (str, list, tuple), None, sets and mappings (dict); types are mutable (list, dict, set) or immutable (int, float, str, tuple).
Operators, input-output and errors
- Arithmetic operators: + − * / (true division) // (floor division) % (remainder) ** (exponent); relational: == != > < >= <=; logical: and, or, not; assignment: = += −= etc.; identity: is, is not; membership: in, not in.
- Precedence: ** has the highest, then unary minus, then * / // %, then + −; for example 2 + 3 * 4 = 14 and 2 ** 3 ** 2 = 512 because ** is right-associative.
- input() always returns a string, so int() or float() is used for explicit conversion; print() displays output, with sep and end parameters. Errors are syntax errors (wrong grammar), logical errors (wrong output) and runtime errors or exceptions (such as ZeroDivisionError).
Key terms
- Interpreter
- a program that executes code line by line
- Identifier
- a user-defined name for a variable, function or other object
- Keyword
- a reserved word with special meaning in Python
- Mutable
- a data type whose value can be changed in place
- Type conversion
- changing a value from one data type to another
Important questions with answers
Distinguish between / and // operators in Python.2 marks
The / operator performs true division and always returns a float, for example 7 / 2 = 3.5. The // operator performs floor division and returns the largest whole number not greater than the result, for example 7 // 2 = 3 and -7 // 2 = -4.
What are mutable and immutable data types? Give examples.3 marks
Mutable data types can be changed after creation without changing their identity, such as list, dict and set. Immutable data types cannot be changed in place; any change creates a new object, such as int, float, bool, str and tuple.
Explain the types of errors in Python with examples.5 marks
Errors in a Python program are of three main types. Syntax errors occur when the rules of the language are not followed, such as a missing colon after an if statement, unmatched parentheses or misspelled keywords; for example, writing print("Hello" without a closing bracket. The interpreter reports a syntax error and the program does not run until it is corrected. Logical errors occur when the program runs without crashing but produces wrong output because the logic is incorrect, for example writing average = a + b / 2 instead of average = (a + b) / 2, which gives a wrong result due to operator precedence. Logical errors are hardest to find because no error message appears, so testing with known answers and dry runs is needed. Runtime errors, also called exceptions, occur during execution when an illegal operation is attempted even though the syntax is correct, for example dividing by zero (ZeroDivisionError), converting a non-numeric string with int() (ValueError), using an undefined variable (NameError) or accessing an index that does not exist (IndexError). Runtime errors stop the program unless they are handled using exception handling with try and except. Good programmers prevent errors by careful design, testing and validation of input.
Quick revision
- Interactive and script mode.
- Keywords, identifiers, variables, data types.
- Operators and precedence.
- Input, output, type conversion, errors.
Exam tips
- Remember: 7 // 2 = 3, 7 % 2 = 1, 7 / 2 = 3.5.
- input() returns a string; convert it with int() before arithmetic.
Practice MCQs
Python was created by
- Dennis Ritchie
- Bjarne Stroustrup
- James Gosling
- Guido van Rossum
Show answer
Answer: (d) Guido van Rossum. It was released in 1991.
The value of 17 % 5 in Python is
- 3
- 3.4
- 2
- 5
Show answer
Answer: (c) 2. % gives the remainder.
Which of these is a valid identifier
- 2total
- total_marks
- for
- total-marks
Show answer
Answer: (b) total_marks. Identifiers cannot start with a digit, be keywords or contain hyphens.
The function input() returns data of type
- int
- float
- str
- bool
Show answer
Answer: (c) str. Convert it explicitly for arithmetic.
Which data type is immutable
- list
- tuple
- dict
- set
Show answer
Answer: (b) tuple. Tuples cannot be changed in place.
The result of 2 + 3 * 4 ** 2 is
- 400
- 50
- 98
- 80
Show answer
Answer: (b) 50. 4 ** 2 = 16, 3 * 16 = 48, 48 + 2 = 50.
The result of 2 ** 3 ** 2 is
- 64
- 12
- 36
- 512
Show answer
Answer: (d) 512. ** is right-associative, so 3 ** 2 = 9 first.
Dividing a number by zero while the program runs causes a
- syntax error
- compile-time warning
- logical error only
- runtime error (ZeroDivisionError)
Show answer
Answer: (d) runtime error (ZeroDivisionError). It is an exception.
All chapters of Class 11 Computer Science
Written by Kundali IQ from standard, well-established facts to help with revision. This is not an official NCERT publication; always read your textbook too.