Chapter 5
Chapter 5
String values are enclosed either in single quotation marks (e.g., ‘Hello’) or in double quotation marks (e.g.,
“Hello”).
The quotes are not a part of the string, they are used to mark the beginning and end of the string for the
Interpreter.
List Type
List is a sequence of items separated by commas and the items are enclosed in square brackets [ ].
Tuple Type
Tuple is a sequence of items separated by commas
and items are enclosed in parenthesis ( ).
This is unlike list, where values are enclosed in
brackets [ ].
Once created, we cannot change the tuple.
Set Type
Set is an unordered collection of items separated by
commas and the items are enclosed in curly
brackets { }.
A set is similar to list, except that it cannot have
duplicate entries.
Once created, elements of a set cannot be changed.
None Type
None is a special data type with a single value.
It is used to signify the absence of value in a
situation.
None supports no special operations, and it is
neither same as False nor 0 (zero).
Mapping:
Dictionary
Mapping: Dictionary in Python holds data items in key-value
pairs.
Mapping is an unordered data type in Python.
Items in a dictionary are enclosed in curly brackets { }.
Currently, there is only one standard mapping data
type in Python called dictionary. Dictionaries permit faster access to data.
Every key is separated from its value using a colon (:)
sign.
The key : value pairs of a dictionary can be accessed
using the key.
The keys are usually strings and their values can
be any data type.
Tuples are used when we do not need any change in the data.
For example, names of months in a year.
When we need uniqueness of elements and to avoid duplicacy it is preferable to use sets,
for example, list of artefacts in a museum.
If our data is being constantly modified or we need a fast lookup based on a custom key or we need a logical
association between the key : value pair, it is advised to use dictionaries. A mobile phone book is a good
application of dictionary.
Operator
An operator is used to perform specific mathematical or logical operation on values.
The values that the operators work on are called operands.
Types of Operators:
1. Arithmetic Operators
2. Relational Operators
3. Assignment Operators
4. Logical Operators
5. Identity Operator
6. Membership Operators
Arithmetic
Operators
Python supports arithmetic operators that are
used to perform the four basic arithmetic
operations as well as modular division, floor
division and exponentiation.
Relational
Operators
Relational operator compares the
values of the operands on its either
side and determines the
relationship among them.
Assume the Python variables num1
= 10, num2
= 0, num3 = 10, str1 =
"Good", str2 =
"Afternoon" for the following
examples:
Assignment
Operators
Assignment operator assigns or changes the value of
the variable on its left.
Logical
Operators
There are three logical operators
supported by Python.
These operators (and, or, not)
are to be written in lower case only. The
logical operator evaluates to either True
or False based on the logical operands on
either side. Every value is logically either
True or False. By default, all values are
True except None, False, 0 (zero), empty
collections "", (), [], {}, and few other
special values. So if we say num1 =
10, num2 = -20, then both num1
and num2 are logically True.
Identity Operator
Identity operators are used to
determine whether the value of a
variable is of a certain type or
not. Identity operators can also
be used to determine whether
two variables are referring to the
same object or not. There
are two identity operators.
Membership Operators
Membership operators are
used to check if a value is a
member of the given
sequence or not.
Expression
DESCRIPTION EXAMPLES
•Explicit Conversion: Manual conversion using functions like int(), float(), str(), etc.
Debugging
The process of identifying and removing mistakes, also known as bugs or errors, from a program is called
debugging.
Types of Errors:
Syntax Errors: Errors in the structure of the code, such as missing colons, parentheses, or incorrect
indentation.
Runtime Errors: Errors that occur during program execution, such as division by zero or accessing a variable
that has not been defined.
Logical Errors: Errors in the logic of the code that produce incorrect results, even though the code runs
without crashing.
Chapter Blueprint
VSA SA LA E TOTAL
2 MCQ 1 1 2 18 MARKS
1 FIB (1 HOT)