0% found this document useful (0 votes)
25 views12 pages

Chapter 2 Python Fundamentals

class 8

Uploaded by

sweetyappu88
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)
25 views12 pages

Chapter 2 Python Fundamentals

class 8

Uploaded by

sweetyappu88
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
You are on page 1/ 12

Chapter2- Python Fundamentals

Fill in the Blanks Questions


1) _variable is a named memory location.
2) A variable is created when a value is assigned with __=__operator.
3) __print()__statement is used to display the value of variables.
4) __keyword_ can not be a variable name.
5) __int__data type can only accept whole numbers.
6) __float__ data types can accept numbers with decimal point.
7) __string__data type can accept sequence of characters in ‘ ‘ or “ “ quotes.
8) ___operators_ are the special symbol which represent computation applied on
operands.
9) operands_ are the values and variables used with operators.
10) A variable in Python is created when a value is assigned to it using the __________
operator.
a. Assignment
11) Variable names in Python must begin with an __________, __________, or
__________.
a. Uppercase letter, lowercase letter, underscore
12) A variable name in Python cannot start with a __________.
a. Digit
13) Special characters like __________, __________, and __________ cannot be used in
Python variable names.
a. !, @, #
14) In Python, all data values are represented by __________.
a. Objects
15) __________ in Python are whole numbers consisting of digits with optional + or -
signs.
a. Integers
16) Numbers with fractions or decimal points are called __________ in Python.
a. Floating-point numbers
17) A __________ is a sequence of characters enclosed in single or double quotes.
a. String
18) A list in Python is a collection of items that are __________.
a. Mutable
19) A __________ in Python is a collection of unique, unordered elements.
a. Set
20) A __________ stores data in key-value pairs.
a. Dictionary
21) The + operator can be used for __________ numbers and __________ strings.
a. Adding, concatenating
22) The * operator can be used for __________ numbers and __________ strings.
a. Multiplying, repeating
23) The // operator performs __________ division in Python.
a. Integer
24) The __________ operator is used to calculate the remainder of a division in Python.
a. % (modulus)
25) The ** operator is used for __________ in Python.
a. Exponentiation
26) The __________ operator checks if two values are equal in Python.
a. ==
27) The __________ operator checks if two values are not equal in Python.
a. !=
28) The > operator checks if the value on the left is __________ than the value on the
right.
a. Greater
29) The < operator checks if the value on the left is __________ than the value on the
right.
a. Less
30) The >= operator checks if the value on the left is __________ or __________ to the
value on the right.
a. Greater, equal
31) The <= operator checks if the value on the left is __________ or __________ to the
value on the right.
a. Less, equal
32) The and operator returns __________ if both conditions are true.
a. True
33) The or operator returns __________ if at least one condition is true.
a. True
34) The not operator __________ the result of a boolean expression.
a. Reverses
35) Indentation in Python is used to define the __________ of the code.
a. Block
36) The if statement is used to execute code __________ in Python.
a. Conditionally
37) The else statement provides an alternative block of code to execute if the if statement's
condition is __________.
a. False
38) The elif statement allows you to check __________ conditions in an if statement.
a. Multiple
39) The for loop in Python is used to __________ over a sequence.
a. Iterate
40) The while loop continues to execute as long as its __________ remains true.
a. Condition
41) The break statement is used to __________ a loop prematurely.
a. Exit
42) The continue statement is used to __________ the current iteration and proceed to the
next one.
a. Skip
43) A function in Python is defined using the __________ keyword.
a. def
44) Python is a __________-sensitive programming language.
a. Case

Multiple choice questions


1) Python support ___ arithmetical operator.
1. Five
2. Six
3. Seven
4. Eight
2) __ operator gives the remainder of an arithmetical expression.
1. /
2. //
3. %
4. \
3) __ operator gives quotient in integer only.
1. /
2. \
3. //
4. \\
4) _____ and ______ category of operator always give result either in true or false.
1. Arithmetical and logical
2. Logical and relational
3. Relational and Arithmetical
4. None
5) The operator for not equal is ___ and ___
1. <> , !=
2. >< , not =
3. Not equal, !=
4. <>, not equal
6) This operator returns result true when both the statements are true.
1. or
2. and
3. not
4. none
7) This operator returns result true if any one of the statement is true.
1. or
2. and
3. not
4. none
8) This operator reverse the result
1. or
2. and
3. not
4. none
9) Which of the following is a valid variable name in Python?
a) 1variable
b) variable_1
c) variable-1
d) variable@1
11) Which of the following is not a valid variable name in Python?
a) Variable
b) _variable
c) variable_
d) var!able
12) What will be the output of the following code?
x=5
print(x)
a) 5
b) x
c) None
d) Error
13) Which statement is used to display the value of a variable in Python?
a) echo()
b) print()
c) show()
d) display()
14) Which of the following is an integer in Python?
a) 10
b) 10.5
c) "10"
d) [10]
15) Which of the following is a floating-point number in Python?
a) 10
b) 10.5
c) "10.5"
d) [10.5]
16) Which data type is used to store a sequence of characters in Python?
a) int
b) float
c) str
d) list
17) Which of the following is a valid string in Python?
a) 'Hello'
b) "Hello"
c) '''Hello'''
d) All of the above
18) Which operator is used for exponentiation in Python?
a) ^
b) **
c) *
d) //
19) What is the result of the following expression?
print(10 % 3)
a) 1
b) 2
c) 3
d) 0

20) What will be the output of the following code?

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) <=

23) What will be the output of the following code?

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"

Assertion and Reasoning Questions for Python Programming


1.  Assertion (A): A variable in Python is created when a value is assigned to it using
the assignment operator (=).

Reason (R): Python requires explicit declaration of variables before assignment.


 (A) is True, (R) is False.

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).

3. Assertion (A): Variable names in Python can begin with a digit.


Reason (R): Variable names in Python must start with a letter (a-z, A-Z) or an
underscore (_).

 (A) is False, (R) is True.

4. Assertion (A): Special characters like !, @, # can be used in Python variable names.
Reason (R): Special characters are not allowed in Python variable names.

 (A) is False, (R) is True.

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 False, (R) is True.

7. Assertion (A): The // operator performs floating-point division in Python.


Reason (R): The // operator performs integer (floor) division in Python.

 (A) is False, (R) is True.

8. Assertion (A): The * operator can be used to repeat strings in Python.


Reason (R): In Python, the * operator is used to multiply numbers and repeat strings.

 (A) is True, (R) is True, and (R) is the correct explanation of (A).

9. Assertion (A): The % operator returns the remainder of a division.


Reason (R): The % operator is used to find the modulus of a division.

 (A) is True, (R) is True, and (R) is the correct explanation of (A).

10. Assertion (A): The ** operator is used for exponentiation in Python.


Reason (R): The ** operator raises the left operand to the power of the right operand.

 (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.

 (A) is False, (R) is True.

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).

17. Assertion (A): Python is a case-insensitive programming language.


Reason (R): Python differentiates between uppercase and lowercase characters in
variable and function names.

 (A) is False, (R) is True.

SHORT QUESTION AND ANSWER


1. What is a variable in Python?
o A variable is a named storage location in memory used to store data that can be
accessed and manipulated in a program.
2. How are variables created in Python?
o Variables are created by assigning a value to them using the assignment
operator =.
3. What are the rules for naming variables in Python?
o Variables must start with a letter (a-z, A-Z) or underscore (_), followed by
letters, digits (0-9), or underscores. They cannot start with a digit or contain
special symbols (!, @, #, $, %).
4. Name the basic data types in Python.
o Numeric types (integers, floating-point, complex numbers), sequences (strings,
lists, tuples), sets, dictionaries, and boolean.
5. How are strings defined in Python?
o Strings are defined with either single ( ') or double (") quotes, enclosing
characters or text.
6. What is the purpose of the print() function in Python?
o The print() function is used to display the value of variables or expressions
to the console.
7. Explain the term 'expression' in Python.
o An expression is a combination of values, variables, and operators that
evaluates to a single value.
8. What is the difference between = and == in Python?
o = is the assignment operator used to assign a value to a variable. == is the
equality operator used to compare two values for equality.
9. What are arithmetic operators in Python?
o Arithmetic operators (+, -, *, /, %, **, //) perform mathematical calculations
like addition, subtraction, multiplication, division, etc.
10. How are comments written in Python?
o Single-line comments start with #, and multi-line comments are enclosed
within triple quotes (""").
11. What is the purpose of the input() function in Python?
o The input() function is used to accept user input from the console, returning
it as a string.
12. What are boolean values in Python?
o Boolean values (True and False) are used to represent truth values in logical
expressions.
13. Explain the term 'operator precedence' in Python.
o Operator precedence determines the order in which operators are evaluated in
expressions. Operators with higher precedence are evaluated first.
14. What are relational operators in Python?
o Relational operators (<, >, <=, >=, ==, !=) compare values and return True or
False based on the comparison.
15. What is the purpose of the and, or, and not operators in Python?
o and returns True if both operands are True, or returns True if at least one
operand is True, and not negates the result..
16. Explain the term 'indentation' in Python.

Indentation refers to the spaces or tabs at the beginning of a code line that defines the
scope of code blocks.

17. What are operators in Python?

Operators in Python are special symbols or keywords that perform operations on


variables and values.

18. How are arithmetic operators used in Python?

Arithmetic operators (+, -, *, /, //, %, **) are used for mathematical calculations like
addition, subtraction, multiplication, division, exponentiation, etc.
19. Explain the use of the assignment operator (=) in Python.

The assignment operator (=) is used to assign a value to a variable, e.g., x = 5.

20. What are comparison operators in Python?

Comparison operators (<, >, <=, >=, ==, !=) are used to compare two values and return
a Boolean result indicating whether the comparison is true or false.

21. How do logical operators (and, or, not) work in Python?

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.

22. What is the difference between = and == in Python?

= is the assignment operator used to assign a value to a variable. == is the equality


operator used to compare two values for equality.

LONG QUESTION AND ANSWER


1. What are variables in Python? How are they created and used?

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'

2. Explain the rules for naming variables in Python.

Answer:

 Variables must start with a letter (uppercase or lowercase) or an underscore (_).


 They can contain letters, digits, or underscores.
 Variable names cannot start with a digit.
 Reserved words (keywords like if, else, for, etc.) cannot be used as variable names.
 Avoid using special characters like !, @, #, $, %, etc.

3. What are the main data types supported in Python? Give examples of each.

Answer: Python supports several built-in data types:

 Numeric Types: int, float, complex


 Sequence Types: str (string), list, tuple
 Set Types: set
 Mapping Type: dict (dictionary)
 Boolean Type: bool

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:

 Arithmetic Operators: Perform mathematical operations (+, -, *, /, //, %, **).


 Relational Operators: Compare values (<, >, <=, >=, !=, ==).
 Logical Operators: Combine conditional statements (and, or, not).
 Assignment Operators: Assign values (=, +=, -=, *=, /=, etc.).

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:

str1 = 'Hello, World!'


str2 = "Python Programming"
str3 = '''This is a multi-line
string in Python'''
str4 = """Another multi-line
string with double quotes"""

7. How do you perform string concatenation in Python? Provide an example.

Answer: String concatenation in Python is done using the + operator. Example:

first_name = 'John'
last_name = 'Doe'
full_name = first_name + ' ' + last_name
print(full_name) # Outputs: John Doe

You might also like