0% found this document useful (0 votes)
5 views5 pages

Python Internal Assessment Questions

The document is a Python internal assessment consisting of 25 multiple-choice questions covering various topics such as function parameters, data types, file handling, recursion, and lambda functions. Each question tests knowledge of Python syntax and functionality. The assessment is designed to evaluate the understanding of fundamental Python concepts.

Uploaded by

Keerthana
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Python Internal Assessment Questions

The document is a Python internal assessment consisting of 25 multiple-choice questions covering various topics such as function parameters, data types, file handling, recursion, and lambda functions. Each question tests knowledge of Python syntax and functionality. The assessment is designed to evaluate the understanding of fundamental Python concepts.

Uploaded by

Keerthana
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON INTERNAL ASSESSMENT

Date: 15/04/2024 Time: 1 ½ hour

1. What is the purpose of the `*args` parameter in a function definition?


A) It specifies default values for arguments
B) It indicates variable positional arguments
C) It is used for keyword arguments
D) It terminates the function execution

2. Which of the following is a correct way to comment in Python?


A) `// This is a comment`
B) `/* This is a comment */`
C) `# This is a comment`
D) `-- This is a comment`

3. How do you declare a variable in Python?


A) `variable x;`
B) `var x;`
C) `x = 10`
D) `declare x = 10`

4. What is the purpose of the `elif` keyword in Python?


A) It stands for "else if" and is used for multiple branching conditions
B) It's a typo and should be avoided
C) It's short for "element if" and is used in list comprehensions
D) It's an acronym for "extend list if" and is used in list operations

5. Which of the following data types is immutable in Python?


A) List
B) Dictionary
C) Tuple
D) Set

6. What is the result of `3 + 4 * 2` in Python?


A) 14
B) 11
C) 22
D) 15

7. What does the `len()` function do in Python?


A) Returns the length of a string
B) Returns the square root of a number
C) Returns the current date and time
D) Returns the largest element in a list

8. How do you open a file named "[Link]" in read mode in Python?


A) `file = open("[Link]", "r")`
B) `file = open("[Link]", "read")`
C) `file = read("[Link]")`
D) `file = open("[Link]")`

9. Which keyword is used for defining a function in Python?


A) func
B) define
C) function
D) def

10. How do you check the type of a variable in Python?


A) `typeOf(variable)`
B) `[Link]()`
C) `type(variable)`
D) `typeof variable`

11. What is the output of `print("Hello" + 3)` in Python?


A) `Hello3`
B) `HelloHelloHello`
C) `Hello 3`
D) Error: cannot concatenate 'str' and 'int' objects

12. Which of the following is the correct way to import the `math` module in Python?
A) `include math`
B) `import math`
C) `use math`
D) `from math import *`

13. What is the purpose of the `range()` function in Python?


A) To generate a sequence of numbers
B) To create a list with a specified range
C) To iterate over a sequence of numbers
D) To define the range of a variable

14. Recursion in programming is:


A) A loop that repeats a set of instructions
B) A function that calls itself
C) An iterator in Python
D) A conditional statement

15. What is the difference between a list and a tuple in Python?


A) Lists are immutable, and tuples are mutable
B) Lists are ordered and mutable, tuples are ordered and immutable
C) Lists are unordered and mutable, tuples are ordered and immutable
D) Lists are ordered and immutable, tuples are unordered and mutable

16. In Python, what does the `+=` operator do?


A) Subtracts the right operand from the left operand
B) Adds the right operand to the left operand
C) Multiplies the left operand by the right operand
D) Divides the left operand by the right operand

17. Which of the following is a valid way to create a dictionary in Python?


A) `dict = {1: 'one', 2: 'two'}`
B) `dictionary = [1='one', 2='two']`
C) `dict = (1, 'one', 2, 'two')`
D) `dictionary = {1, 'one', 2, 'two'}`

18. What is the purpose of the `random` module in Python?


A) To perform random arithmetic operations
B) To generate random numbers and data
C) To shuffle elements in a list
D) To create random strings

19. What is the result of `2 ** 3` in Python?


A) 5
B) 6
C) 8
D) 16

20. Which of the following is a correct syntax for a lambda function in Python?
A) `lambda x, y: x + y`
B) `function(x, y): x + y`
C) `lambda x + y`
D) `def lambda(x, y): return x + y`

21. What is the main advantage of using a lambda function?


A) It can have multiple lines of code
B) It can be used as a standalone function or inside other functions
C) It is always more efficient than regular functions
D) It can be called recursively

22. Which keyword is used to call a recursive function within itself?


A) `call`
B) `execute`
C) `self`
D) The function name

23. In Python, what does the `map` function do when used with a lambda function?
A) It performs element-wise addition
B) It applies the lambda function to each element of an iterable
C) It creates a new dictionary
D) It sorts the elements of an iterable
24. What is the result of the following recursive function?
``` def
factorial(n):
if n == 0:
return 1 else:
return n * factorial(n - 1)
```
A) It calculates the square of the input
B) It calculates the factorial of the input
C) It calculates the sum of the input
D) It results in an infinite loop

25. What is the output of the following code snippet?


```
square = lambda x: x**2
print(square(4))
```
A) 8
B) 16
C) 2
D) 12

You might also like