Chapter 2 Python Fundamentals
Chapter 2 Python Fundamentals
x = 10
y=3
print(x // y)
a) 3.3333
b) 3.0
c) 3
d) Error
21) Which operator is used to compare two values for equality in Python?
a) =
b) ==
c) !=
d) <>
22) Which operator is used to check if one value is less than another in Python?
a) >
b) <
c) >=
d) <=
x = 10
y = 20
print(x > y)
a) True
b) False
c) 10
d) 20
24) What will be the output of the following code?
x = 15
y = 15
print(x >= y)
a) True
b) False
c) 15
d) Error
25) Which of the following comparisons will return False?
a) 5 < 10
b) 10 == 10
c) 20 > 30
d) 15 != 20
26) Which logical operator is used to combine multiple conditions in Python?
a) and
b) or
c) not
d) All of the above
27) What will be the output of the following code?
x = 10
y=5
print(x > y and y > 0)
a) True
b) False
c) 10
d) 5
28) What will be the output of the following code?
x = 10
y = 20
print(x > y or y > x)
a) True
b) False
c) 10
d) 20
29) Which logical operator inverts the result of a condition in Python?
a) and
b) or
c) not
d) invert
30) What will be the output of the following code?
x = 10
print(not (x > 5))
a) True
b) False
c) 10
d) Error
31) Which of the following is not a valid statement in Python?
a) x = 5
b) print(x)
c) x + y
d) print(x > y)
32) What will be the output of the following code?
x = "Python"
print(x * 2)
a) PythonPython
b) Python*2
c) 2Python
d) Error
33) Which of the following is a valid assignment statement in Python?
a) x == 10
b) x = 10
c) 10 = x
d) x === 10
34) How do you concatenate (join) two strings Hello and World?
a) "Hello" + "World"
b) "Hello" - "World"
c) "Hello" * "World"
d) "Hello" / "World"
2. Assertion (A): The print() statement is used to display the values of variables.
Reason (R): The print() statement in Python is used to display output to the
console.
(A) is True, (R) is True, and (R) is the correct explanation of (A).
4. Assertion (A): Special characters like !, @, # can be used in Python variable names.
Reason (R): Special characters are not allowed in Python variable names.
5. Assertion (A): Strings in Python can be enclosed in either single or double quotes.
Reason (R): Both single and double quotes are used to denote string literals in
Python.
(A) is True, (R) is True, and (R) is the correct explanation of (A).
6. Assertion (A): The + operator can only be used for numerical addition in Python.
Reason (R): The + operator is also used for string concatenation in Python.
(A) is True, (R) is True, and (R) is the correct explanation of (A).
(A) is True, (R) is True, and (R) is the correct explanation of (A).
(A) is True, (R) is True, and (R) is the correct explanation of (A).
11. Assertion (A): The == operator checks for value equality in Python.
Reason (R): The == operator compares two values and returns True if they are equal.
(A) is True, (R) is True, and (R) is the correct explanation of (A).
12. Assertion (A): The != operator checks if two values are equal.
Reason (R): The != operator returns True if the two values compared are not equal.
13. Assertion (A): The and operator returns True if both conditions are true.
Reason (R): The and operator performs a logical AND operation.
(A) is True, (R) is True, and (R) is the correct explanation of (A).
14. Assertion (A): The or operator returns True if at least one condition is true.
Reason (R): The or operator performs a logical OR operation.
(A) is True, (R) is True, and (R) is the correct explanation of (A).
15. Assertion (A): The not operator returns False if the condition is true.
Reason (R): The not operator inverts the truth value of a condition.
(A) is True, (R) is True, and (R) is the correct explanation of (A).
16. Assertion (A): Indentation in Python is used to define the block of code.
Reason (R): Indentation helps in identifying the scope of loops, functions, and
conditionals.
(A) is True, (R) is True, and (R) is the correct explanation of (A).
Indentation refers to the spaces or tabs at the beginning of a code line that defines the
scope of code blocks.
Arithmetic operators (+, -, *, /, //, %, **) are used for mathematical calculations like
addition, subtraction, multiplication, division, exponentiation, etc.
19. Explain the use of the assignment operator (=) in Python.
Comparison operators (<, >, <=, >=, ==, !=) are used to compare two values and return
a Boolean result indicating whether the comparison is true or false.
Logical operators combine multiple conditions. and returns True if both conditions are
true. or returns True if at least one condition is true. not returns the opposite Boolean
value.
Answer: Variables in Python are named memory locations used to store data. They are
created by assigning a value to a name using the assignment operator (=). Unlike some other
languages, Python does not require explicit declaration of variables before use. For example:
python
Copy code
x = 10 # Here, 'x' is a variable storing the integer value 10
name = 'Alice' # 'name' is a variable storing the string 'Alice'
Answer:
3. What are the main data types supported in Python? Give examples of each.
Examples:
num = 10 # int
pi = 3.14 # float
name = 'Alice' # str
my_list = [1, 2, 3] # list
my_tuple = (4, 5, 6) # tuple
my_set = {7, 8, 9} # set
my_dict = {'a': 1, 'b': 2} # dict
is_true = True # bool
4. Discuss the concept of operators in Python. What are the main categories of
operators?
Answer: Operators in Python are special symbols that perform operations on operands
(variables and values). The main categories are:
5. How do you create strings in Python? Provide examples of different ways to define
strings.
Answer: Strings in Python can be defined using single quotes (') or double quotes (").
Examples:
first_name = 'John'
last_name = 'Doe'
full_name = first_name + ' ' + last_name
print(full_name) # Outputs: John Doe