Python 1
List, String & Functions in Python
Class VIII
TECH ASSESSMENT
A. Tick (✓) the correct option.
1. Items in a list with five elements will have an index from ________.
Answer: (b) 0 to 4
2. The method used to remove an item from a list is __________.
Answer: (c) Both (a) and (b)
3. Which of the following method is used to add an item to a list?
Answer: (c) Both (a) and (b)
4. Which of the following is not a string function?
Answer: (c) del
B. Fill in the blanks.
1. A list is a data type similar to an array.
2. A function can accept arguments also.
3. In Python, statements in the function are written with indentation.
4. The dot (.) operator is used to execute a particular method for a string.
C. Write ‘T’ for true and ‘F’ for false for the following statements.
1. A list can hold only one type of data. → False
2. You cannot change the values of a list. → False
3. Built-in functions are already created in the Python library. → True
4. You can also define a function according to your requirements. →True
D. Short Answer Questions.
1. What is the use of list?
Answer: A list is used to store multiple values in a single variable. It can store different types of
data and allows modification. The different items in the list are separated by commas.
2. What is the purpose of using a parameter?
Answer: A parameter is a variable that allows a function to receive input values so that it can
perform operations using those values.
3. What is the use of functions in a program?
Answer: A function is a block of related statements to perform a specific task. It helps to organize
code, avoid repetition, and make programs easier to read, test, and maintain.
4. What are built-in functions?
Answer: In python, some functions are already available for use. These functions are called
built-in functions. Some examples of built-in functions are `print()`, `len()`, and `type()`.
E. Long Answer Questions.
1. Explain any five string functions.
lower() – It converts all characters to lowercase.
upper() – It converts all characters to uppercase.
title() – It converts first letter of each word to uppercase.
replace() – It replaces part of a string with another value.
find() – It returns the position of a substring.
2. Explain functions for the following:
Deleting a list (del):
The del keyword is used to delete an entire list variable from memory. Once deleted, the
variable no longer exists and trying to access it will result in a NameError.
Example: del my_list
Inserting an item (insert()):
The insert() method adds an element at a specific index. Unlike append(), which only adds
to the end, insert() shifts all subsequent elements to the right to make room for the new
item.
Example: [Link](index, element)
Clearing a list (clear()):
The clear() method removes all elements from the list, leaving it empty. Unlike deleting the
list, the list object itself still exists in memory and can be reused.
Example: my_list.clear( )
3. What is the significance of returning data in functions? Explain with an example.
Returning data allows a function to send a result back to the place where it was called. This
makes functions reusable and useful for calculations. Without the return statement, a Python
function effectively returns none.
Example:
def add(a, b):
return a + b
result = add(5, 3)
print(result)
Output: `8`
Here, the function returns the sum so it can be used later in the program.
Python 2
Loops & Statements in Python
Class VIII
TECH ASSESSMENT
A. Tick (✓) the correct option.
1. Which of the following is a type of statement in Python?
Answer: (c) Both of these
2. Which of the following is a selection statement?
Answer: (c) both of these
3. Each execution of a loop is called
Answer: (b) iteration
4. The statement is used to go ahead to the next iteration without executing the remaining
statements in the loop.
Answer: (a) continue
B. Fill in the blanks.
1. Sequence statements are used to execute statements in a specific order.
2. The if statement evaluates the test expression and will execute the body only when the
test condition is true.
3. The while statement is also known as the entry control loop statement.
4. The continue statement is used to go to the next iteration without executing the
remaining statements in the loop.
C. Write ‘T’ for true and ‘F’ for false
1. The jump statements are used to check the conditions. →False
2. The continue statement is a type of iterative statement. →False
3. The if...elif...else is a conditional statement. →True
4. The range function is used to generate a series of numbers. →True
D. Short Answer Questions
1. What is a statement?
A statement is a single instruction given to the python interpreter to perform a specific task. In
other words, instructions are called statements.
2. Name the types of statements in Python.
The types of statements in Python are:
Sequence statements
Selection (Conditional) statements
Iteration (Looping) statements
Jump statements
3. Differentiate between break and continue statements.
Break Continue
Terminates the loop completely. Skips the current iteration and
moves to the next iteration.
Control comes out of the loop. Control remains inside the loop.
E. Long Answer Questions
1. What is the difference between the ‘if’ and ‘if…else’ statements?
Sl.
if if-else
No.
1. if statement allows us to execute a if-else statement allows us to execute
code block when the condition is different code blocks based on whether the
True. condition is True or False.
2. if statement does nothing in case if-else statement executes the statements
condition evaluates to False. indented below else when the condition is
False.
2. Explain the range() function using an example.
The Python range() function generates an immutable sequence of integers, commonly used for
looping a specific number of times.
Syntax and Parameters
The range() function accepts up to three integer arguments:
range(start, stop, step)
start (optional): The starting number of the sequence (inclusive). The default is 0 if
omitted.
stop (required): The number at which the sequence ends (exclusive). The sequence
stops before this value is reached.
step (optional): The difference between consecutive numbers in the sequence. The default
is 1 if omitted. This value cannot be zero.
3. Explain the while loop using an example.
A while loop in Python repeatedly executes a block of code as long as a specified condition
remains True. It is typically used when the number of iterations needed is not known in
advance.
Example:
Source Code:
i=1
while i <= 5:
print(i)
i += 1
Output:
12345
The loop runs until the condition i <= 5 becomes false.