Which of the following numbers depict the given clip?

- Real Number
- Imaginary Number
- Complex Number
- Floating Number
Answer
Complex Number
Reason — The given clip represents a complex number, which is the combination of a real number and an imaginary number. In Python, it is expressed as , where represents the real part and represents the imaginary part with .
Given: m = 24
What is the data type of the given Python variable?
- String
- Integer
- Float
- Double
Answer
Integer
Reason — The value 24 is a whole number without a decimal point. All whole numbers (positive or negative) without a decimal point are said to be of integer (int) type in Python.
Which data type in Python is used to store a sequence of characters?
- Char
- String
- Text
- Word
Answer
String
Reason — In Python, a string is defined as a collection of one or more characters enclosed within single, double or triple quotes. It is used to store a sequence of characters.
Which of the following is the correct representation to define a list in Python?
- Elements are written using curly braces { }
- Elements are written using parentheses ( )
- Elements are written using square brackets [ ]
- Elements are written using angle brackets < >
Answer
Elements are written using square brackets [ ]
Reason — In Python, a list is defined as an ordered sequence of one or more data items separated by commas and enclosed within square brackets [ ].
Which of the following data type would be used for a variable to store the value 3.14 in Python?
- int
- decimal
- double
- float
Answer
float
Reason — The value 3.14 is a fractional number with a decimal point. All fractional numbers are said to be of float type in Python, also known as floating point numbers.
Which of the following data types would be used in Python to store values in terms of key and value?
- list
- tuple
- dictionary
- String
Answer
dictionary
Reason — In Python, a dictionary is an unordered set of elements where data is stored as "Key:Value" pairs, enclosed within curly brackets { }.
Given My_Data = [12, 25, 'Hello', "World"]
What data type is the representation of the above object?
- list
- dictionary
- array
- tuple
Answer
list
Reason — The elements are enclosed within square brackets [ ] and contain data items of different types (integers and strings) separated by commas, which represents a list in Python.
Which of the following is a mutable data type in Python?
- Strings
- Tuples
- Lists
- Integers
Answer
Lists
Reason — Lists in Python are mutable, meaning their elements can be altered, added, or removed after the list is created. Strings, tuples and integers are immutable in Python.
Which of the following data types does not allow duplicate values in Python?
- Lists
- Dictionaries
- Tuples
- Sets
Answer
Sets
Reason — A set in Python is a built-in data type that represents an unordered collection of unique elements. It automatically removes duplicate elements when present.
Boolean data is used to test a particular condition i.e., True or False.
Which of the following is the correct representation?
- boolean m=True
- boolean m='True'
- boolean m="True"
- none of them
Answer
none of them
Reason — In Python, there is no 'boolean' keyword used while declaring a variable. The Boolean values True or False are assigned directly to a variable (e.g., m = True) without enclosing them in quotes. Hence, none of the given representations are correct.
State whether the following statements are True or False:
- Comments are executable statements.
- The import statements are used to include modules or libraries into the program to accomplish tasks.
- Operators are the symbols or tokens to perform various mathematical or logical operations on data.
- All whole numbers (positive or negative numbers) without a decimal point are said to be float type numbers.
- The tuple is an ordered set of elements containing one or more data items of the same or different types.
- In Python, we cannot assign the same integer value to different variables.
- Python is case sensitive and thus it treats uppercase and lowercase letters differently.
- Boolean constants are special literals and represent only two Boolean values.
Answer
- False
Corrected Statement: Comments are non-executable statements. - True
- True
- False
Corrected Statement: All whole numbers (positive or negative numbers) without a decimal point are said to be int (integer) type numbers. - True
- False
Corrected Statement: In Python, we can assign the same integer value to different variables. - True
- True
Name the following constants as defined in Python:
| Constants | Name of the constant |
|---|---|
| 0.00345 | |
| 'A' | |
| True | |
| -999 |
Answer
| Constants | Name of the constant |
|---|---|
| 0.00345 | Floating Point Constant |
| 'A' | String Constant |
| True | Boolean Constant |
| -999 | Integer Constant |
Predict the output and type of casting for the given Python expressions:
| Python Expression | Explicit/Implicit |
|---|---|
| m = 32.005, n = 45 print(int(m+n)) | |
| a = 42.85, b = 12.45 print(a+b) |
Answer
| Python Expression | Output | Explicit/Implicit |
|---|---|---|
| m = 32.005, n = 45 print(int(m+n)) | 77 | Explicit |
| a = 42.85, b = 12.45 print(a+b) | 55.30 | Implicit |
Predict the output when executed:
Given: list1 = ['Robotics', 2026, 'ICSE', 'Edition']
| Statement | Output |
|---|---|
| print(list1) | |
| print(list1[0]) | |
| print(list1[1:3]) | |
| print(list1[2:]) |
Answer
| Statement | Output |
|---|---|
| print(list1) | ['Robotics', 2026, 'ICSE', 'Edition'] |
| print(list1[0]) | Robotics |
| print(list1[1:3]) | [2026, 'ICSE'] |
| print(list1[2:]) | ['ICSE', 'Edition'] |
Predict the output when executed:
| Statement | Output |
|---|---|
| a = 24 m = float(a) print(m) | |
| b = 32.86 n = int(b) print(n) | |
| c = 3 p = complex(c) print(p) |
Answer
| Statement | Output |
|---|---|
| a = 24 m = float(a) print(m) | 24.0 |
| b = 32.86 n = int(b) print(n) | 32 |
| c = 3 p = complex(c) print(p) | (3+0j) |
Assertion (A): Variable is a named memory location which contains a value.
Reason (R): When you create a variable, it reserves some space in the memory.
Based on the above discussion, choose an appropriate statement from the options given below:
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true and R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
- Both A and R are false.
Answer
Both A and R are true and R is the correct explanation of A.
Reason — A variable is a named memory location which contains a value. When a variable is created, the system reserves some space in the memory to store its value, and this memory location is identified by the variable name. Hence, R correctly explains why A is true.
In Python programming, it is an unordered collection data type that is iterable, mutable and has no duplicate elements. It is represented by { } where the values are enclosed in curly braces.
Read the above paragraph and answer the following questions:
(a) Name the data type that is used in Python.
(b) What will happen, if duplicate elements are present in this data types and executed?
Answer
(a) The data type used in Python is Set.
(b) If duplicate elements are present in a set and executed, the set will automatically remove the duplicates and retain only the unique values. This is because a set does not allow duplicate elements. For example, executing My_set = {"red", "blue", "green", "yellow", "blue", "green"} will result in {"red", "blue", "green", "yellow"} being stored, as the duplicate values "blue" and "green" are eliminated.
Write short notes on Indentation.
Answer
Indentation is the fundamental aspect of Python programming that defines the structure and flow of code. Unlike many other programming languages that use curly braces { } or keywords to delimit blocks of code, Python relies on indentation levels to group statements. It refers to the aligning of a statement or group of statements which are part of another statement to get the desired execution of a specific block. All the statements within a block must be indented by the same amount, and it is a common practice to use 4 spaces per indentation level. Mixing tabs and spaces is not allowed and will result in an Indentation Error. Therefore, proper indentation is crucial in Python as it directly affects the execution of the code and its readability.
Write short notes on Assignment.
Answer
Assignment means to store values in variables using a token '='. Here, the symbol '=' acts as an assignment operator. The 'equal to' sign (=) is used to assign values to the variables. The operand to the left of the '=' operator is the variable name and the operand to the right of the '=' operator is the value to be stored.
Syntax: <variable> = <value>
For example:
m = 15: 15 is stored in the variable m which is of integer type.n = 45.24: 45.24 is stored in the variable n which is of float type.ch = 'k': The letter 'k' is stored as a string character in variable ch.wd = "Computer Science": A word is stored in the variable wd.
Write short notes on Boolean Constant.
Answer
Boolean constants are special literals that represent only two Boolean values, i.e., True or False. They can be used in a Python code to check whether a given logical condition is satisfied or not. The Boolean constants are written with their initial characters in capital letters (i.e., 'T' or 'F'). Writing them in lowercase (true or false) is incorrect and will raise an error in Python. It must be noted that Boolean constants (True or False) are never enclosed within single or double quotes. This characteristic makes Boolean constants different from string constants.
Write short notes on Variable.
Answer
A variable is a named memory location which contains a value. When a variable is created, it reserves some space in the memory to store the data. The value of a variable can change depending upon the requirements in a program. For example, n = 25 means that the integer value 25 is assigned to the variable 'n', and the data value 25 will be stored in the memory location identified by the name 'n'. Whenever we refer to 'n', we will get 25. However, the value of 'n' can be changed at any time, and when a variable is reassigned with a new value, the original value will get replaced by the new value.
Name the components which are essentially involve in the basic structure of Python programming.
Answer
The components essentially involved in the basic structure of Python programming are as follows:
- Comments — Non-executable statements used to explain the purpose of the code.
- Import Statements — Used to include modules or libraries into the program.
- Variables — Used to store data in memory for performing various tasks and later use.
- Data Types — Built-in types like integers, floats, strings, boolean, lists, tuple, etc.
- Operators — Symbols or tokens to perform various mathematical or logical operations on data.
- Control Structures — Used to control the flow of instructions (if-else, for loops, while loops).
- Functions — Used to group related statements together and give them a name for reuse.
What is meant by data type?
Answer
Data types are referred to as the classification or categorisation of data items. They represent a particular type of value which determines what operations can be performed on that particular data. Python supports several built-in data types including integers, floats, strings, boolean, lists, tuples, sets and dictionaries to perform various tasks during programming.
In what ways Python data types are categorised?
Answer
Python data types are categorised into the following groups:
- Numeric — Represents data with numeric values. It includes:
- Integer (int): whole numbers without a decimal point.
- Float: fractional numbers with a decimal point.
- Complex: combination of a real number and an imaginary number.
- Non-Numeric — Includes Boolean data type (True or False).
- Sequences — Ordered collection of items, includes:
- String
- List
- Tuple
- Sets — Unordered collection of unique elements.
- Dictionary — Unordered set of key-value pairs.
Explain the following data types:
(a) String
(b) List
(c) Tuple
(d) Dictionary
Answer
(a) String: In Python, a string is defined as a collection of one or more characters enclosed within single, double or triple quotes. When a string is assigned to a variable, each character sets itself to an index and can be accessed individually with reference to memory locations. The index starts from 0 in the forward direction and from -1 in the backward direction.
For example: wd = "Artificial Intelligence"
(b) List: A list is defined as an ordered sequence of one or more data items of the same or different data types. The data items in a list are separated by commas and enclosed within square brackets [ ]. One of the most important features of a list is that it is mutable, i.e., an element can be altered in its place. The values can be accessed with their indices, starting from the 0th index till the (length – 1)th index.
For example: list1 = ['Python', 2026, 'Edition', 'ICSE']
(c) Tuple: Like a list, a tuple is also an ordered set of elements containing one or more data items of the same or different types. The data items in a tuple are separated by commas but enclosed within parentheses ( ). The main difference between lists and tuples is that a list is mutable (can be modified) whereas a tuple is immutable (the elements cannot be updated).
For example: tuple1 = ('Robotics', 'Artificial', 'Intelligence', 'with', 'Python')
(d) Dictionary: A dictionary is an unordered set of elements where data is stored as keys along with their corresponding values. Every key has its corresponding value, forming a pair in the form of Key:Value. The collection of such pairs is enclosed within curly brackets { }. Generally, dictionary keys are strings, whereas values can be any arbitrary Python object.
For example: dict = {"Robotics":1, "Artificial":2, "Intelligence":3, "with":4, "Python":5}
What is meant by Python Sets? Explain with the help of an example.
Answer
In Python, a set is a built-in data type that represents an unordered collection of unique elements. Sets are used to store multiple items in a single variable, with elements enclosed within curly braces { } and separated by commas. A set is unordered, unchangeable (in terms of modifying individual elements) and unindexed.
Characteristics of a Set:
- Unordered: The elements do not have a specific order, so they may appear in different orders.
- Unique Elements: A set automatically removes duplicate elements.
- Mutable: Elements can be added or removed from a set after its creation.
Example:
My_set = {"red", "blue", "green", "yellow"}
print(My_set)
Output: {'red', 'green', 'yellow', 'blue'}
If we try adding duplicates, the set will retain only unique values. For example, My_set = {"red", "blue", "green", "yellow", "blue", "green"} will store only {'red', 'blue', 'green', 'yellow'}.
What are the rules to assign a variable in a Python code?
Answer
The rules to assign a variable in a Python code are as follows:
- A variable may have any number of characters.
- A variable name cannot start with a number, but it can start with characters or an underscore (e.g.,
_rollnum). - The underscore can be used in between the characters to separate the words of a variable name (e.g.,
reg_no). - The variable names should be meaningful, which easily explains their purpose.
- Python is case sensitive. So, it treats uppercase and lowercase letters differently (e.g.,
Nameandnameare different variables).
Explain each of the following with an example:
(i) Implicit type conversion
(ii) Explicit type conversion
Answer
(i) Implicit Type Conversion: In a mixed mode expression, the result gets automatically converted into the highest data type available in the expression, without any intervention from the user. This system of conversion is known as implicit type conversion or coercion.
Example:
a = 15; b = 4; c = 12.4
ans = (a + b) - c
print(ans)
Here, (a + b) gives an integer (int – int = int), then int – float gives a float. So, the result is 6.6 (float type), obtained automatically without any user intervention.
(ii) Explicit Type Conversion: Explicit type conversion is another way of type conversion, in which one data type gets converted into another data type depending upon the user's choice. When the data type is converted after the user's intervention, the conversion is known as explicit type conversion or type casting.
Example:
a = 32; b = 12; c = 4
ans = int((a - b) / c)
print(ans)
Here, (a - b) / c would normally give 5.0 (float). But the user explicitly applies int() to forcibly convert it to int type, resulting in 5. This forceful conversion by the user is called type casting.
How will you assign multiple objects to multiple variables? Explain with the help of an example.
Answer
Python language facilitates assigning multiple objects to multiple variables in a single statement. The values may be of mixed data types like integer, floating point numbers, strings, etc. This is done by separating the variables and their corresponding values with commas.
Syntax: var1, var2, var3 = value1, value2, value3
Example:
m, n, wd = 146, 2020, "Computer"
print(m)
print(n)
print(wd)
Output:
146
2020
Computer
Here, two integers with values 146 and 2020 are assigned to the variables m and n respectively, and one string with the value "Computer" is assigned to the variable wd, all in a single statement.