ADUP
ADUP
ADUP
(APPLICATION DEVELOPMENT USING
PYTHON)
MCQs
print(my_list[2])
A) apple
B) 2
C) 3
D) Error
Answer: C) 3
Answer: C) range()
add = lambda x, y: x + y
print(add(3, 4))
A) 34
B) 7
C) lambda x, y: x + y
D) Error
Answer: B) 7
print(squares)
A) [1, 4, 9]
B) [0, 1, 4, 9]
C) [1, 4, 9, 16]
D) [1, 2, 3]
Answer: A) [1, 4, 9]
my_set = {1, 2, 3}
my_set.add(4)
print(my_set)
By: Akatsuki
3
A) {1, 2, 3, 4}
B) [1, 2, 3, 4]
C) (1, 2, 3, 4)
D) {4, 3, 2, 1}
Answer: A) {1, 2, 3, 4}
Q10: Which of the following methods removes an element from a set without
throwing an error if the element does not exist?
A) remove()
B) pop()
C) discard()
D) delete()
Answer: C) discard()
print(i)
A) 1 2 3 4 5
B) 2 3 4 5
C) 2 3 4 5 6
D) 3 4 5 6
Answer: B) 2 3 4 5
Q12: Which loop is best suited when the number of iterations is unknown?
A) for loop
B) while loop
C) do-while loop
D) if-else loop
By: Akatsuki
4
print(my_dict["name"])
A) name
B) John
C) Error
D) 25
Answer: B) John
Answer: C) def
return x * y
print(multiply(2))
A) 2
B) 5
C) 10
D) Error
Answer: C) 10
Answer: D) <>
print(10 // 3)
A) 3.33
B) 3
C) 4
D) Error
By: Akatsuki
5
Answer: B) 3
Answer: B) import
import math
print(math.sqrt(16))
A) 16
B) 4
C) 8
D) Error
Answer: B) 4
1. What are the unique features of Python that make it popular among developers?
Python is widely used due to its simplicity, versatility, and powerful libraries. The key
features that make Python popular are:
• Python uses a simple syntax similar to the English language, making it easy to
learn and use.
• Example:
2. Interpreted Language:
• Python does not need compilation like C or Java. Instead, it runs line by line,
making debugging easier.
3. Dynamically Typed:
• Example:
x = 10 # Integer
By: Akatsuki
6
• Python has a wide range of libraries such as NumPy, Pandas, TensorFlow, and
Django, which help in AI, data science, web development, and more.
6. Platform-Independent:
5 / 2 → 2 (floor division by
Integer Division 5 / 2 → 2.5 (true division)
default)
By: Akatsuki
7
Example Differences:
# Python 2
# Python 3
Python 3 is the modern version and is recommended for all development work.
A. Identifiers in Python
1. Must start with a letter (A-Z, a-z) or underscore (_) but cannot start with a
number.
Example:
B. Keywords in Python
• False, None, True, and, as, assert, break, class, continue, def, del, elif, else,
except, finally, for, from, global, if, import, in, is, lambda, nonlocal, not, or, pass,
raise, return, try, while, with, yield
By: Akatsuki
8
C. Indentation in Python
• Unlike other languages that use {} or ;, Python uses indentation to define code
blocks.
if True:
if True:
4. Explain different types of Linux files. How can you get user input in Python and
work with different data types?
3. Special Files:
By: Akatsuki
9
x = 10 # Integer
y = 10.5 # Float
z = "Hello" # String
Type casting means converting a variable from one data type to another.
x = 10 # int
y = 10.5 # float
num = 10
num_str = "100"
By: Akatsuki
10
• Lists:
A list in Python is a collection that is ordered, mutable, and allows duplicate
elements. Lists are defined using square brackets []. Example:
print(my_list[0]) # Output: 1
• Ranges:
A range in Python is used to generate a sequence of numbers. It is commonly
used in loops and is defined using the range() function. Example:
print(i)
# Output: 1 2 3 4
• Tuples:
A tuple is a collection that is ordered, immutable, and allows duplicate
elements. It is defined using parentheses (). Example:
print(my_tuple[1]) # Output: 2
By: Akatsuki
11
• Example:
• square = lambda x: x * x
• print(square(5)) # Output: 25
• Lambda functions are useful for short, throwaway functions that do not need to
be explicitly named.
• List Comprehension:
• Dictionary Comprehension:
print(squares_dict)
• Set Comprehension:
my_set = {1, 2, 3}
By: Akatsuki
12
my_set.add(4)
my_set.remove(2)
• For Loop:
Used to iterate over a sequence (list, tuple, range, etc.).
print(i)
• While Loop:
Runs as long as a condition is True.
x=1
while x <= 5:
print(x)
x += 1
By: Akatsuki