12 Class- Exception Handling in Python

What are exceptions?
Exceptions are events that occur during program execution that disrupt the normal flow of the program and can lead to errors. Examples of exceptions include division by zero, invalid input, file not found, etc.

Handling exceptions
In Python, exceptions can be handled using the try-except block. The code that might raise an exception is placed inside the try block, and the code to handle the exception is placed inside the except block.

Types of exceptions
Python has many built-in exceptions, including NameError, TypeError, ValueError, ZeroDivisionError, etc. It is also possible to create custom exceptions using the raise statement.

Raising exceptions
Developers can raise exceptions manually using the raise statement. This is useful when an error occurs that cannot be handled by the program, and it needs to be passed on to a higher-level function or the user.

Finally block
The finally block is a piece of code that is executed whether or not an exception is raised. It is typically used for cleanup code, such as closing files or releasing resources.

Exception hierarchy
Python has a hierarchy of exception classes, with the base class being Exception. This allows developers to catch multiple exceptions at once using a single except block.

Debugging
Exception handling is an essential tool for debugging Python programs. By handling exceptions gracefully, developers can identify and fix errors in their code more easily.

Page : 1           2           3           4

Class 10 Artificial Intelligence Unit 1 Introduction to Artificial Intelligence

Class 10 Artificial Intelligence Unit 1 Introduction to Artificial Intelligence Session 1 : Foundational Concepts of Artificial Intelligence MCQs and Question Answers

Unit 1 Introduction to Artificial Intelligence

Session 1 : Foundational Concepts of Artificial Intelligence

Multipole choice Questions  and Question Answers

1. To make decisions, _________ is necessary.
(a) Information (b) Intelligence (c) Both a and b (d) Programming

Answer: (b) Intelligence

2. What stimulates us to initiate the process of reasoning?
(a) Process (b) Sensing (c) Reasoning (d) Programming

Answer: (b) Sensing

3. The processing of what we sense is called ______?
(a) Process (b) Sensing (c) Reasoning (d) Programming

Answer: (c) Reasoning

4. A man-made thing is called _______?
(a) Artificial (b) Ready Made (c) Intelligence (d) Artificial Intelligence

Answer: (a) Artificial.

5. To be able to learn different languages ________ intelligence is required.
(a) Spatial visual (b) Existential (c) Linguistic (d) Naturalist

Answer: (c) Linguistic

6. To be able to interact and related with the surroundings and environment is _______ intelligence
(a) Naturalist (b) Climate (c) Intrapersonal (d) None

Answer: (c) Naturalist

7. Ability to understand the logic, theories, formulae, and expressions is _______ intelligence
(a) Naturalist (b) Climate (c) Intrapersonal (d) Mathematical and Logical

Answer: (d) Mathematical and Logical

8. Communicating with others with an understanding of ow they feel and perceive is _______ intelligence
(a) Interpersonal (b) Intrapersonal (c) Existential (d) Mathematical and Logical

Answer: (a) Interpersonal

9. Amrit has the ability to create, identify and understand rhymes and patterns. He is having _______ intelligence
(a) Naturalist (b) Climate (c) Intrapersonal (d) Musical

Answer: (d) Musical

10. Intelligence is directly related to ______.
(a) Fact (b) Learning (c) Brain (d) None

Answer: (b) Learning

11. Intelligence can be defined as ______.
(a) Ability to interact with the real-world

(b) Reasoning and Planning

(c) Learning and adaptation

(d) All of the above

Answer: (d) All of the above

Question Answers – 1 Mark & 2 Marks.

1. What is Artificial? (1 Mark)
Answer: Artificial is something that is man-made, which does not occur naturally.

2. What is Intelligence? (1 Mark)
Answer: Intelligence is the ‘ability to perceive or infer information, and to retain it as knowledge to be applied towards adaptive behaviours within an environment or context.’

Intelligence is the ability to observe and understand information, and preserve it as knowledge to apply in various situations or context through suitable adaptive behaviours.

3. What simulates us initiating the process of reasoning? (1 Mark)
Answer: Sensing

4. What is reasoning? (1 Mark)
Answer: The process of sensing (i.e. input – through sense, perceive, receive ) is known as reasoning.

5. How many types of reasoning? (1 Mark)
Answer: There are two types of reasoning – Deductive and Inductive

6. Define:- Deductive and Inductive? (2 Marks)
Answer: Deductive: In deductive reasoning facts are analysed and guarantee a conclusion.

Inductive: In inductive reasoning, facts only support the conclusion without any guarantee.

7. By which organ a human can sense? (1 Mark)
Answer: A human can sense through receptive organs (eye, ear, nose, mouse, skin, etc).

8. How a machine can sense? (1 Mark)
Answer: Machine can sense through the following sensing devices –

Image scanner, Audio sensor, Speech recognition engine, Biometric sensor, motion sensor, thermal sensor, light sensor, Proximity (distance) sensor, etc.

9. What are the different traits/characteristics/types of intelligence? (2 Marks)
Answer: The abilities/traits that are involved in intelligence are: –

Natural Intelligence
Interpersonal Intelligence
Intrapersonal Intelligence
Musical Intelligence
Mathematical Logical Reasoning Intelligence
Linguistics Intelligence
Spatial Visual Intelligence
Kinaesthetic Intelligence
Existential Intelligence
10. What is Mathematical Logical Reasoning intelligence? (1 Mark)
Answer: A person’s ability to regulate, measure, and understand numerical symbols, abstraction, and logic, known as Mathematical Logical Reasoning. Mathematical Logical Reasoning are carried out in the left, back and front of the brains.

11. What is Linguistic intelligence? (1 Mark)
Answer: Linguistic Intelligence means language processing skills both in terms of understanding or implementation in writing or verbally.

12. What is Spatial Visual intelligence? (1 Mark)
Answer: Spatial Visual intelligence is the ability to perceive the visual world and the relationship of one object to another.

13. What is Kineasthetic intelligence? (1 Mark)
Answer: Kinaesthetic Intelligence is the ability that is related to how a person uses his limbs in a skilled
manner.

14. What is Musical intelligence? (1 Mark)
Answer: Musical Intelligence is about a person’s ability to recognize and create sounds, rhythms, and sound patterns

15. What is Intrapersonal intelligence? (1 Mark)
Answer: Intrapersonal Intelligence describes how high the level of self-awareness someone has. Starting from realizing weakness, and strength, to his own feelings

16. What is Interpersonal intelligence? (1 Mark)
Answer: Interpersonal Intelligence is the ability to communicate with others by understanding other people’s feelings & influence the person.

17. What is Existential intelligence? (1 Mark)
Answer: Existential Intelligence is an additional category of intelligence relating to religious and spiritual awareness.

18. What is Naturalist intelligence? (1 Mark)
Answer: Naturalist Intelligence is an additional category of intelligence relating to the ability to process the information of the environment around us.

19. What is the difference between Interpersonal intelligence and Intrapersonal Intelligence? (1 Mark)
Answer: Interpersonal Intelligence involves interpersonal skills, communication skills, and ability to interact with others, while Intrapersonal intelligence involves the skills of self-awareness, self-discipline, self-management, self-evaluation, etc.

20. What is AI? (1 Mark)
Answer: AI is the science and engineering of making Intelligent machines.

21. What do you mean by AI? (1 Mark)
Answer: AI refers to the study of principles, concepts and technology for building such machines and systems that should think, act and learn like humans.

22. What are the AI challenges to making machine intelligence? (2 Marks)
Answer: AI challenges are

Retain the facts as knowledge
Recall the knowledge in a situation.
Think, analyse and apply logic.
Make useful and accurate predictions.
Make decisions and upgrade their intelligence algorithm themselves.

23. How do machines become artificially intelligent? (1 Mark)
Answer: Machine becomes intelligent once they are trained with some information that helps them achieve their tasks.

AI machines also keep updating their knowledge to optimise their output.

24. What is the most important part of intelligence? (1 Mark)
Answer: Decision Making

25. What is decision-making? (1 Mark)
Answer: Decision-making is the capability that helps in taking the right decisions in different situations.

The basis of decision-making depends upon the availability of information and how we experience and understand it.

26. You are locked inside a room with 3 doors to move out of the locked room and you need to find a safe door to get your way out. (2 Mark)
Behind the 1st door is a lake with a deadly shark.
The 2nd door has a mad psychopath ready to kill with a weapon and
The third one has a lion that has not eaten since the last 2 months.?
Answer: Gate number 3.

The reason being that since the lion has not eaten for 2 months, he wouldn’t have survived till now and would already be dead.

27. What is Artificial intelligence? (1 Mark)
Answer: When a machine possesses the ability to mimic human traits, i.e., make decisions, predict the future, learn and improve on its own, it is said to have artificial intelligence.

OR

A machine is artificially intelligent when it can accomplish tasks by itself – collect data, understand it, analyze it, learn from it, and improve it.

28. Write the name of Applications of Artificial Intelligence around us? (2 Marks)
Answer: Articificially Intelligence applications are-

(a) Google Assitant (b) Auto Suggest and auto-corrects (c) Cortana (d) Siri (e) Google Maps (f) Weather forecast (g) Real Time Language Translators (h) Sophia (i) Biometric Security Sensor

29. Give the example of voice assistance? ( 2 Marks)
Answer: Voice Assistants are – (a) Google Assitant (b) Cortana (c) Siri (d) Alexa

30. How do machines become Artificially Intelligent? ( 2 Marks)
Answer: Machines become intelligent once they are trained with some information that helps them achieve their tasks.

AI machines also keep updating their knowledge to optimise their output.

31. How do humans become intelligent? (1 Marks)
Answer: Humans become more and more intelligent with time as they gain experiences during their lives.

32. Give two examples where Google is using the concept of AI? (2 Marks)
Answer: (i) Google Search (ii) Auto suggests & Auto corrects.

33. Give 4 examples of pocket voice assistants. (2 Marks)
Answer: Very common examples of pocket voice assistants are Alexa, Google Assistant, Cortana, and Siri.

34. Give one example which helps in direction. (1 Mark)
Answer: Google Map

35. How AI changes the experiences of Gaming? (1 Marks)
Answer: A lot of games nowadays are backed up with AI which helps in enhancing the graphics, coming up with new difficulty levels, encouraging gamers, etc. For example: EA Sports (FIFA)

36. How AI taking care of our habits, like & dislike ? (2 Marks)
Answer: AI has not only made our lives easier but has also been taking care of our habits, likes, and dislikes. Due to AI following changes are noticed in our daily life: –

Netflix, Amazon, Spotify, YouTube, etc. show us recommendations on the basis of what we like.
Cater to our needs of connecting with friends on social media platforms with apps like Facebook and Instagram.
Send us customized notifications about our online shopping details, auto-create playlists according to our requests, and so on.
Taking selfies was never this fun as Snapchat filters make them look so cool

37. How AI helps in health? (1 Marks)
Answer: AI is also being used to monitor our health. A lot of chatbots and other health apps are available, which continuously monitor the physical and mental health of its users.

Arguments of Python

Arguments of Python

1.What is an argument in Python?

A. A variable declared inside a function
B. A value passed to a function when calling it
C. A method used to modify an object
D. A conditional statement used in a loop

Answer :B
Explanation: B. An argument in Python refers to a value passed to a function when calling it.

2.What is a default argument in Python?

A. A variable declared inside a function
B. A value passed to a function when calling it
C. A value assigned to a parameter in a function definition
D. A method used to modify an objectA


Answer :C
Explanation: C. A default argument in Python is a value assigned to a parameter in a function definition, which is used if no argument is passed for that parameter when calling the function.

3.How can you define a function in Python with arguments?

A. def function_name():
B. def function_name(arguments):
C. def function_name(*arguments):
D. def function_name(arguments,*args):

Answer : D
Explanation: D. You can define a function in Python with arguments by using the syntax def function_name(arguments,*args):, where “arguments” refers to the required arguments and “*args” refers to any additional arguments.

4.What is a keyword argument in Python?

A. An argument passed by its name instead of position
B. An argument that must be passed to a function
C. An argument that is optional when calling a function
D. An argument that has a default value

Answer :A
Explanation: A. A keyword argument in Python is an argument passed by its name instead of position, which allows you to specify the value of any parameter by its name.

5.What is a variable-length argument in Python?

A. An argument passed by its name instead of position
B. An argument that must be passed to a function
C. An argument that is optional when calling a function
D. An argument that can take any number of values

Answer 😀
Explanation: D. A variable-length argument in Python is an argument that can take any number of values, which is defined using the syntax *args in a function definition.

6.What is the purpose of the **kwargs argument in Python?

A. To pass a variable number of arguments to a function
B. To pass keyword arguments to a function
C. To define a function that takes a variable number of arguments
D. To define a function that takes keyword arguments

Answer :B
Explanation: B. The **kwargs argument in Python is used to pass keyword arguments to a function.

7.How can you pass arguments to a Python function as a tuple?

A. By using the syntax *args when calling the function
B. By using the syntax **kwargs when calling the function
C. By using the syntax *args in the function definition
D. By using the syntax **kwargs in the function definition

Answer :A
Explanation: A. You can pass arguments to a Python function as a tuple by using the syntax *args when calling the function, which converts the arguments to a tuple.


8.How can you pass arguments to a Python function as a dictionary?

A. By using the syntax *args when calling the function
B. By using the syntax **kwargs when calling the function
C. By using the syntax *args in the function definition
D. By using the syntax **kwargs in the function definition

Answer :B
Explanation: B. You can pass arguments to a Python function as a dictionary by using the syntax **kwargs when calling the function, which converts the arguments to a dictionary.

9.Can a Python function have both required and optional arguments?

A. Yes, a function can have both required and optional arguments.
B. No, a function can only have either required or optional arguments.
C. It depends on the version of Python being used.
D. It depends on the type of function being defined.

Answer :A
Explanation: A. A Python function can have both required and optional arguments by defining the required arguments first, followed by any optional arguments with default values.

10.How can you pass a list as an argument to a Python function?

A. By passing the list as a comma-separated series of values
B. By enclosing the list in square brackets when calling the function
C. By using the syntax *args when calling the function
D. By using the syntax **kwargs when calling the function

Answer :B
Explanation: B. You can pass a list as an argument to a Python function by enclosing the list in square brackets when calling the function.

11.What is the purpose of the * operator in Python function arguments?

A. To unpack a list or tuple into separate arguments
B. To pack a list or tuple into a single argument
C. To pass a dictionary as an argument
D. To specify a required argument

Answer :A
Explanation: A. The * operator in Python function arguments is used to unpack a list or tuple into separate arguments.

12.What is the purpose of the ** operator in Python function arguments?

A. To unpack a list or tuple into separate arguments
B. To pack a list or tuple into a single argument
C. To pass a dictionary as an argument
D. To specify a required argument

Answer :C
Explanation: C. The ** operator in Python function arguments is used to pass a dictionary as an argument.

13.Can you specify the order of optional arguments in a Python function?

A. Yes, the order of optional arguments can be specified in a Python function.
B. No, the order of optional arguments is always fixed.
C. It depends on the version of Python being used.
D. It depends on the type of function being defined.

Answer :A
Explanation: A. The order of optional arguments in a Python function can be specified by defining the required arguments first, followed by the optional arguments with default values in the desired order.

14.What is the purpose of the *args and **kwargs arguments in a Python function?

A. To pass a variable number of arguments to a function
B. To define a function that takes a variable number of arguments
C. To pass keyword arguments to a function
D. To specify the order of optional arguments in a function

Answer :A
Explanation: A. The *args and **kwargs arguments in a Python function are used to pass a variable number of arguments and/or keyword arguments to a function.

15.What is the difference between a mutable and immutable object in Python?

A. A mutable object can be changed after it is created, while an immutable object cannot be changed.
B. A mutable object can only be changed using the del statement, while an immutable object cannot be changed.
C. A mutable object can only be changed using a method, while an immutable object cannot be changed.
D. A mutable object cannot be used as an argument to a function, while an immutable object can.

Answer :A
Explanation: A. The difference between a mutable and immutable object in Python is that a mutable object can be changed after it is created, while an immutable object cannot be changed.a

16.What is the purpose of the * symbol when used with a list in Python?

A. To pack the list into a single argument
B. To unpack the list into separate arguments
C. To convert the list to a tuple
D. To reverse the order of the elements in the list

Answer :B
Explanation: B. The * symbol when used with a list in Python is used to unpack the list into separate arguments.

17.What is the difference between keyword arguments and positional arguments in Python?

A. Keyword arguments are optional, while positional arguments are required.
B. Keyword arguments are specified using a keyword, while positional arguments are specified based on their position.
C. Keyword arguments are always passed as dictionaries, while positional arguments are always passed as tuples.
D. There is no difference between keyword arguments and positional arguments.

Answer :B
Explanation: B. The difference between keyword arguments and positional arguments in Python is that keyword arguments are specified using a keyword, while positional arguments are specified based on their position.

Arguments of Python

18.Can a Python function have a default value for a required argument?

A. Yes, a function can have a default value for a required argument.
B. No, a function cannot have a default value for a required argument.
C. It depends on the version of Python being used.
D. It depends on the type of function being defined.

Answer :B
Explanation: B. A required argument in Python cannot have a default value. If a default value is specified, the argument becomes optional.

19.What is the purpose of the * operator in Python function calls?

A. To unpack a list or tuple into separate arguments
B. To pack a list or tuple into a single argument
C. To pass a dictionary as an argument
D. To specify a required argument

Answer :A
Explanation: A. The * operator in Python function calls is used to unpack a list or tuple into separate arguments.

20.What is the purpose of the ** operator in Python function calls?

A. To unpack a list or tuple into separate arguments
B. To pack a list or tuple into a single argument
C. To pass a dictionary as an argument
D. To specify a required argument

Answer :C
Explanation: C. The ** operator in Python function calls is used to pass a dictionary as an argument.

21.What is the difference between a function and a method in Python?

A. A function is defined inside a class, while a method is defined outside of a class.
B. A function operates on objects of a specific type, while a method operates on the class as a whole.
C. A function is a standalone block of code, while a method is associated with an object or class.
D. There is no difference between a function and a method.

Answer :C
Explanation: C. The difference between a function and a method in Python is that a function is a standalone block of code, while a method is associated with an object or class.

22.Can a Python function take no arguments?

A. Yes, a function can take no arguments in Python.
B. No, a function must always take at least one argument.
C. It depends on the version of Python being used.
D. It depends on the type of function being defined.

Answer :A
Explanation: A. A Python function can take no arguments by simply defining the function with no parameters.

23.Can a Python function take an infinite number of arguments?

A. Yes, a function can take an infinite number of arguments in Python.
B. No, a function can only take a finite number of arguments.
C. It depends on the version of Python being used.
D. It depends on the type of function being defined.

Answer :A
Explanation: A. A Python function can take an infinite number of arguments by using the *args or **kwargs syntax.

24.What is the purpose of the lambda keyword in Python?

A. To define a function
B. To define a class
C. To define a variable
D. To define a loop

Answer :A
Explanation: A. The lambda keyword in Python is used to define a function, specifically an anonymous function that can be defined in one line.

25.What is the purpose of the *args syntax in a Python function definition?

A. To specify required arguments
B. To specify keyword arguments
C. To specify an arbitrary number of positional arguments
D. To specify an arbitrary number of keyword arguments

Answer :C
Explanation: C. The *args syntax in a Python function definition is used to specify an arbitrary number of positional arguments.

26.What is the purpose of the **kwargs syntax in a Python function definition?

A. To specify required arguments
B. To specify keyword arguments
C. To specify an arbitrary number of positional arguments
D. To specify an arbitrary number of keyword arguments

Answer 😀
Explanation: D. The **kwargs syntax in a Python function definition is used to specify an arbitrary number of keyword arguments.

27.What is the difference between a mutable and immutable object in Python?

A. A mutable object can be changed after it is created, while an immutable object cannot be changed.
B. A mutable object cannot be changed after it is created, while an immutable object can be changed.
C. A mutable object is a subclass of an immutable object.
D. There is no difference between a mutable and immutable object.

Answer :A
Explanation: A. The difference between a mutable and immutable object in Python is that a mutable object can be changed after it is created, while an immutable object cannot be changed. Examples of mutable objects include lists and dictionaries, while examples of immutable objects include strings and tuples.

28.What is the purpose of the * operator in Python function definitions?

A. To unpack a list or tuple into separate arguments
B. To pack a list or tuple into a single argument
C. To specify a required argument
D. To specify a keyword argument

Answer :B
Explanation: B. The * operator in Python function definitions is used to pack a list or tuple into a single argument.

29.What is the purpose of the ** operator in Python function definitions?

A. To unpack a list or tuple into separate arguments
B. To pack a list or tuple into a single argument
C. To specify a required argument
D. To specify a keyword argument

Answer 😀
Explanation: D. The ** operator in Python function definitions is used to specify a keyword argument.

30.What is the purpose of the default argument value in a Python function definition?

A. To specify a required argument
B. To specify a keyword argument
C. To specify a default value for an optional argument
D. To specify a default value for a required argument

Answer :C
Explanation: C. The purpose of the default argument value in a Python function definition is to specify a default value for an optional argument. If the argument is not specified by the caller, it will use the default value.

31.What is the purpose of the * symbol when used in a function call in Python?

A. To unpack a list or tuple into separate arguments
B. To pack a list or tuple into a single argument
C. To specify a required argument
D. To specify a keyword argument

Answer :A
Explanation: A. The * symbol when used in a function call in Python is used to unpack a list or tuple into separate arguments.

32.What is the purpose of the ** symbol when used in a function call in Python?

A. To unpack a list or tuple into separate arguments
B. To pack a list or tuple into a single argument
C. To specify a required argument
D. To specify a keyword argument

Answer :B
Explanation: B. The ** symbol when used in a function call in Python is used to pack a list or tuple into a single argument.

33.Which of the following is not a valid way to pass arguments to a Python function?

A. By position
B. By keyword
C. By reference
D. As a default value

Answer :C
Explanation: C. Passing arguments to a Python function by reference is not a valid option. Arguments are passed by value in Python, which means that the function receives a copy of the argument, not the original object.

34.What is the purpose of the *args and **kwargs syntax in a Python function call?

A. To specify required arguments
B. To specify keyword arguments
C. To specify an arbitrary number of positional and keyword arguments
D. To specify a default value for an optional argument

Answer :C
Explanation: C. The *args and **kwargs syntax in a Python function call is used to specify an arbitrary number of positional and keyword arguments.

Arguments of Python

35.What is the difference between *args and **kwargs in Python?

A. *args is used for positional arguments and **kwargs is used for keyword arguments.
B. *args is used for keyword arguments and **kwargs is used for positional arguments.
C. *args is used for an arbitrary number of positional arguments and **kwargs is used for an arbitrary number of keyword arguments.
D. There is no difference between *args and **kwargs in Python.

Answer :C
Explanation: C. The difference between *args and **kwargs in Python is that *args is used for an arbitrary number of positional arguments, while **kwargs is used for an arbitrary number of keyword arguments.

36.Which of the following is not a valid way to specify a default value for an argument in a Python function definition?

A. default=None
B. default=[]
C. default={}
D. default=()

Answer 😀
Explanation: D. Using default=() is a valid way to specify a default value for a function argument in Python.

37.What is the purpose of the *args syntax in a Python function definition?

A. To specify required arguments
B. To specify keyword arguments
C. To specify an arbitrary number of positional arguments
D. To specify a default value for an optional argument

Answer :C
Explanation: C. The *args syntax in a Python function definition is used to specify an arbitrary number of positional arguments.

38.What is the purpose of the **kwargs syntax in a Python function definition?

A. To specify required arguments
B. To specify keyword arguments
C. To specify an arbitrary number of positional arguments
D. To specify a default value for an optional argument

Answer :B
Explanation: B. The **kwargs syntax in a Python function definition is used to specify keyword arguments.

39.Which of the following is true about Python function argument order?

A. Required positional arguments must come before optional positional arguments.
B. Optional positional arguments must come before required positional arguments.
C. Keyword arguments must come before positional arguments.
D. Positional arguments must come before keyword arguments.

Answer :A
Explanation: A. In Python, required positional arguments must come before optional positional arguments in a function definition.

Variables And Operators of Python

Variables And Operators of Python

1.What is the correct syntax to declare a variable in Python?

a) var = 5
b) variable = 5
c) variable == 5
d) var 5

Answer: b) variable = 5

Explanation: In Python, the syntax to declare a variable is to write the variable name followed by an equal sign and the value you want to assign to the variable. Therefore, option b) is the correct syntax to declare a variable in Python.

2.What is the modulus operator used for in Python?

a) It multiplies two numbers.
b) It divides two numbers.
c) It returns the remainder of a division operation.
d) It performs exponentiation.

Answer: c) It returns the remainder of a division operation.

Explanation: The modulus operator (%) returns the remainder of a division operation. For example, 7 % 3 would return 1, because 3 goes into 7 twice with a remainder of 1.

3.Which operator is used for exponentiation in Python?

a) *
b) ^
c) **
d) //

Answer: c) **

Explanation: The double asterisk operator (**) is used for exponentiation in Python. For example, 2 ** 3 would return 8, because 2 to the power of 3 is 8.


4.What is the difference between the “==” operator and the “=” operator in Python?

a) The “==” operator assigns a value to a variable, while the “=” operator compares two values for equality.
b) The “==” operator compares two values for equality, while the “=” operator assigns a value to a variable.
c) The “==” operator performs addition, while the “=” operator performs assignment.
d) The “==” operator performs multiplication, while the “=” operator performs division.


Answer: b) The “==” operator compares two values for equality, while the “=” operator assigns a value to a variable.

Explanation: The “==” operator is used to compare two values for equality. For example, 5 == 5 would return True, because 5 is equal to 5. The “=” operator is used to assign a value to a variable. For example, x = 5 would assign the value of 5 to the variable x.

5.What is the result of the following operation: 10 / 3 ?

a) 3.33
b) 3
c) 3.0
d) 4

Answer: a) 3.33

Explanation: In Python, when you divide two integers, the result will be a float if the division results in a decimal. Therefore, the result of 10 / 3 would be 3.33.

6.Which operator is used for floor division in Python?

a) *
b) //
c) %
d) **


Answer: b) //

Explanation: The double slash operator (//) is used for floor division in Python. Floor division returns the largest integer less than or equal to the result of the division operation. For example, 7 // 3 would return 2, because the largest integer less than or equal to 2.33 is 2.

7.What is the order of precedence for arithmetic operators in Python?

a) +, -, *, /, %, **
b) **, *, /, %, +, –
c) *, /, %, +, -, **
d) **, %, *, /, +, –

Answer: b) **, *, /, %, +, –

Explanation: In Python, the order of precedence for arithmetic operators is as follows: exponentiation (**), multiplication (*), division (/), modulus (%), addition (+), and subtraction (-).

8.What is the result of the following operation: 5 * 2 ** 3?

a) 16
b) 40
c) 80
d) 256

Answer: c) 80

Explanation: In Python, exponentiation has a higher order of precedence than multiplication. Therefore, the expression 2 ** 3 will be evaluated first, resulting in 8. Then, the expression 5 * 8 will be evaluated, resulting in 40. Therefore, the final result is 40.

9.What is the result of the following operation: 15 % 4?

a) 3
b) 3.75
c) 4
d) 3.5

Answer: a) 3

Explanation: The modulus operator (%) returns the remainder of a division operation. In this case, 15 divided by 4 is 3 with a remainder of 3. Therefore, the result of 15 % 4 is 3.

10.Which of the following is a valid variable name in Python?

a) 1st_place
b) first_place
c) first-place
d) FirstPlace

Answer: b) first_place

Explanation: In Python, variable names must begin with a letter or underscore. They can then be followed by any combination of letters, numbers, and underscores. Therefore, option b) first_place is a valid variable name in Python. Option a) 1st_place is invalid because variable names cannot begin with a number. Option c) first-place is invalid because variable names cannot contain hyphens. Option d) FirstPlace is valid, but not the recommended convention as the convention for variable names in Python is lowercase_with_underscores.

11.What is the result of the following operation: 4 + 5.0?

a) 9
b) 9.0
c) 45
d) TypeError

Answer: b) 9.0

Explanation: In Python, when you add an integer to a float, the result will be a float. Therefore, the result of 4 + 5.0 would be 9.0.

12.What is the result of the following operation: 2 ** 3 ** 2?

a) 64
b) 512
c) 40353607
d) 134217728

Answer: d) 134217728

Explanation: In Python, exponentiation has right-to-left associativity. Therefore, the expression 3 ** 2 will be evaluated first, resulting in 9. Then, the expression 2 ** 9 will be evaluated, resulting in 512. Therefore, the final result is 512.

13.Which operator is used to check if two values are not equal in Python?

a) !=
b) ==
c) =
d) <>

Answer: a) !=

Explanation: The “!=” operator is used to check if two values are not equal in Python. For example, 5 != 3 would return True, because 5 is not equal to 3.

14.Which operator is used to concatenate two strings in Python?

a) +
b) –
c) *
d) /

Answer: a) +

Explanation: The plus operator (+) is used to concatenate two strings in Python. For example, “hello” + “world” would result in the string “helloworld”.

15.What is the result of the following operation: 10 // 3.0?

a) 3.33
b) 3
c) 3.0
d) 4

Answer: b) 3

Explanation: In Python, when you perform floor division on an integer and a float, the result will be a float. Therefore, the expression 10 // 3.0 would first perform floor division, resulting in 3, and then return the result as a float because one of the operands is a float.

16.Which operator is used to compare two values and return True if the first value is greater than the second value in Python?

a) >
b) <
c) ==
d) >=

Answer: a) >

Explanation: The greater than operator (>) is used to compare two values and return True if the first value is greater than the second value in Python. For example, 5 > 3 would return True, because 5 is greater than 3.

17.What is the result of the following operation: 7 / 2?

a) 3.5
b) 3
c) 4
d) 2

Answer: a) 3.5

Explanation: In Python, when you divide two integers, the result will be a float if the division results in a decimal. Therefore, the result of 7 / 2 would be 3.5.

Variables And Operators of Python

18.Which operator is used to perform logical AND in Python?

a) &&
b) &
c) ||
d) |

Answer: b) &

Explanation: The ampersand (&) operator is used to perform logical AND in Python. For example, (5 > 3) & (7 < 10) would return True, because both expressions evaluate to True.

19.What is the result of the following operation: 3 + 4 * 2?

a) 10
b) 14
c) 11
d) 24

Answer: b) 14

Explanation: In Python, the order of precedence for arithmetic operators is as follows: exponentiation (**), multiplication (*), division (/), modulus (%), addition (+), and subtraction (-). Therefore, the multiplication operation (4 * 2) will be performed first, resulting in 8. Then, the addition operation (3 + 8) will be performed, resulting in 11. Therefore, the final result is 14.

20.Which of the following is a valid way to initialize a variable in Python?

a) variable x = 5
b) x = 5
c) x == 5
d) set x to 5


Answer: b) x = 5

Explanation: In Python, you can initialize a variable by simply assigning a value to it using the equals sign (=). Therefore, option b) x = 5 is a valid way to initialize a variable in Python. Option a) is invalid because variable names cannot have spaces, and the correct syntax is “variable_name = value”. Option c) is a comparison operation and will not initialize a variable. Option d) is not valid Python syntax.

21.Which operator is used to perform logical OR in Python?

a) &&
b) |
c) ||
d) &

Answer: c) ||

Explanation: The double vertical bar (||) operator is not used to perform logical OR in Python. The correct operator to use for logical OR is the double pipe (||) operator. For example, (5 > 3) || (7 < 10) would return True, because at least one of the expressions evaluates to True.

22.What is the result of the following operation: 5 % 2?

a) 2.5
b) 2
c) 1.5
d) 1

Answer: d) 1

Explanation: In Python, the modulus operator (%) returns the remainder of integer division. Therefore, the result of 5 % 2 would be 1, because 5 divided by 2 is 2 with a remainder of 1.a

23.Which operator is used to compare two values and return True if the first value is less than or equal to the second value in Python?

a) <=
b) >=
c) !=
d) ==a

Answer: a) <=

Explanation: The less than or equal to operator (<=) is used to compare two values and return True if the first value is less than or equal to the second value in Python. For example, 3 <= 5 would return True, because 3 is less than or equal to 5.

24.What is the result of the following operation: “hello” * 3?

a) “hellohellohello”
b) “hello3”
c) 9
d) TypeError

Answer: a) “hellohellohello”

Explanation: In Python, when you multiply a string by an integer, the result will be a new string that consists of the original string repeated the specified number of times. Therefore, the result of “hello” * 3 would be the string “hellohellohello”.

25.Which of the following is a valid way to declare a floating-point variable in Python?

a) float x = 5.0
b) x = float(5.0)
c) x = 5
d) x = “5.0”

Answer: b) x = float(5.0)

Explanation: In Python, you can convert an integer or a string to a float by using the float() function. Therefore,
option b) x = float(5.0) is a valid way to declare a floating-point variable in Python.
Option a) is invalid because variable names cannot have spaces, and the correct syntax is “variable_name = value”.
Option c) initializes a variable as an integer, not a float.
Option d) initializes a variable as a string, not a float.

26.Which operator is used to perform exponentiation in Python?

a) ^
b) **
c) *
d) //

Answer: b) **

Explanation: The double asterisk (**) operator is used to perform exponentiation in Python. For example, 2 ** 3 would return 8, because 2 to the power of 3 is 8.

27.What is the result of the following operation: “hello” + “world”?

a) “helloworld”
b) “hello world”
c) “hello+world”
d) TypeError

Answer: a) “helloworld”

Explanation: In Python, when you use the plus (+) operator to concatenate two strings, the result will be a new string that consists of the two original strings combined. Therefore, the result of “hello” + “world” would be the string “helloworld”.

28.Which of the following is a valid way to declare a boolean variable in Python?

a) x = true
b) x = False
c) x = TRUE
d) x = 0

Answer: b) x = False

Explanation: In Python, the boolean values are True and False, with the first letter capitalized. Therefore, option b) x = False is a valid way to declare a boolean variable in Python. Option a) is invalid because the value should be capitalized as False. Option c) is invalid because TRUE is not a valid boolean value in Python. Option d) initializes a variable as an integer, not a boolean.

29.What is the result of the following operation: “hello”[1]?

a) “h”
b) “e”
c) “l”
d) “o”

Answer: b) “e”

Explanation: In Python, you can access individual characters in a string by using indexing. Indexing starts at 0, so “hello”[1] refers to the second character in the string, which is “e”.

30.Which operator is used to perform floor division in Python?

a) //
b) /
c) %
d) **

Answer: a) //

Explanation: The double slash (//) operator is used to perform floor division in Python. Floor division returns the quotient of a division operation, rounded down to the nearest integer. For example, 7 // 2 would return 3, because 7 divided by 2 is 3 with a remainder of 1.

31.Which of the following is NOT a valid variable name in Python?

a) my_variable
b) 123variable
c) MY_VARIABLE
d) _my_variable

Answer: b) 123variable

Explanation: In Python, variable names must start with a letter or an underscore, and can only contain letters, numbers, and underscores. Therefore, option b) 123variable is not a valid variable name in Python because it starts with a number.a

32.What is the result of the following operation: 4 + 2 * 3?

a) 18
b) 10
c) 16
d) 24

Answer: b) 10

Explanation: In Python, when you have multiple operators in a single expression, the order of operations (PEMDAS) is followed: Parentheses, Exponents, Multiplication and Division (from left to right), Addition and Subtraction (from left to right). Therefore, in the expression 4 + 2 * 3, the multiplication is performed first, resulting in 6, and then the addition is performed, resulting in 10.

33.Which operator is used to perform logical NOT in Python?

a) !
b) &&
c) ||
d) &

Answer: a) !

Explanation: The exclamation mark (!) operator is used to perform logical NOT in Python. It is placed in front of a boolean expression and returns the opposite boolean value. For example, !(5 > 3) would return False, because 5 is greater than 3, but the exclamation mark reverses the result to False.

34.What is the result of the following operation: len(“hello”)?

a) “hello”
b) 5
c) 6
d) TypeError

Answer: b) 5

Explanation: In Python, the len() function returns the number of items in a sequence. For strings, it returns the number of characters in the string. Therefore, the result of len(“hello”) would be 5, because “hello” has five characters.

Variables And Operators of Python

35.Which of the following is a valid way to declare an integer variable in Python?

a) x = 3.0
b) x = “3”
c) x = int(3)
d) x = 3++

Answer: c) x = int(3)

Explanation: In Python, you can convert a float or a string to an integer by using the int() function. Therefore, option c) x = int(3) is a valid way to declare an integer variable in Python. Option a) initializes a variable as a float, not an integer. Option b) initializes a variable as a string, not an integer. Option d) is not a valid syntax in Python.

36.What is the result of the following operation: 5 % 2?

a) 2.5
b) 2
c) 3
d) 1.5

Answer: d) 1

Explanation: In Python, the percent (%) operator is used to perform modulus, which returns the remainder of a division operation. Therefore, the result of 5 % 2 would be 1, because 5 divided by 2 is 2 with a remainder of 1.

37.Which operator is used to perform identity comparison in Python?

a) ==
b) !=
c) is
d) not

Answer: c) is

Explanation: The “is” operator is used to perform identity comparison in Python. It tests if two variables refer to the same object in memory. For example, if you have two variables x and y that both point to the same list object [1,2,3], then x is y would return True because they refer to the same object.

38.What is the result of the following operation: 4 / 2?

a) 2.0
b) 2
c) 1.5
d) 0.5

Answer: a) 2.0

Explanation: In Python, the division operator (/) performs floating-point division, which means that it returns a float value even if both operands are integers. Therefore, the result of 4 / 2 would be 2.0, which is a float value.

39.Which of the following is a valid way to declare a string variable in Python?

a) x = ‘hello’
b) x = “hello”
c) x = ”’hello”’
d) All of the above

Answer: d) All of the above

Explanation: In Python, you can declare a string variable using either single quotes (”), double quotes (“”) or triple quotes (”’ ”’). All three options are valid and produce the same result.

40.What is the result of the following operation: 2 ** 0.5?

a) 1.41
b) 1
c) 2
d) TypeError

Answer: a) 1.41

Explanation: In Python, the double asterisk (**) operator is used to perform exponentiation. When you raise a number to a fractional power, it performs a square root operation. Therefore, 2 ** 0.5 would return the square root of 2, which is approximately 1.41.

Data Types of python

Data type of Python

1.What is a data type in Python?

a. A way to represent different types of data in a program
b. A way to represent data that can be used for calculations
c. A way to represent data that can be stored in a database
d. None of the above

Answer: a. A way to represent different types of data in a program

Explanation: A data type is a classification of data in programming. Python has various built-in data types for representing data in a program.

2. Which data type is used to represent a single character in Python?

a. string
b. integer
c. character
d. None of the above

Answer: a. string

Explanation: In Python, a string is used to represent a sequence of characters. A single character can also be represented as a string

3. Which data type is used to represent a sequence of characters in Python?

a. string
b. integer
c. character
d. None of the above

Answer: a. string

Explanation: In Python, a string is used to represent a sequence of characters.

4.Which data type is used to represent whole numbers in Python?

a. float
b. complex
c. integer
d. None of the above

Answer: c. integer

Explanation: In Python, integers are used to represent whole numbers.

5. Which data type is used to represent floating point numbers in Python?

a. float
b. complex
c. integer
d. None of the above

Answer: a. float

Explanation: In Python, floating point numbers are represented using the float data type.

6.Which data type is used to represent complex numbers in Python?

a. float
b. complex
c. integer
d. None of the above

Answer: b. complex

Explanation: In Python, complex numbers are represented using the complex data type.

7.Which data type is used to represent Boolean values in Python?

a. bool
b. boolean
c. bit
d. None of the above

Answer: a. bool

Explanation: In Python, Boolean values are represented using the bool data type.

8.Which data type is used to represent a sequence of elements in Python?

a. list
b. tuple
c. set
d. None of the above

Answer: a. list

Explanation: In Python, a list is used to represent a sequence of elements.

9.Which data type is used to represent an ordered sequence of elements in Python?

a. list
b. tuple
c. set
d. None of the above

Answer: b. tuple

Explanation: In Python, a tuple is used to represent an ordered sequence of elements.

10.Which data type is used to represent an unordered collection of unique elements in Python?

a. list
b. tuple
c. set
d. None of the above

Answer: c. set

Explanation: In Python, a set is used to represent an unordered collection of unique elements.

11.Which data type is used to represent a mapping of keys to values in Python?

a. list
b. tuple
c. set
d. dictionary

Answer: d. dictionary

Explanation: In Python, a dictionary is used to represent a mapping of keys to values.

12.Which data type is used to represent a sequence of bytes in Python?

a. bytes
b. bytearray
c. str
d. None of the above

Answer: a. bytes

Explanation: In Python, the bytes data type is used to represent a sequence of bytes.

13.Which data type is used to represent a file in Python?

a. file
b. fileobject
c. filepointer
d. None of the above

Answer: d. None of the above

Explanation: In Python, a file is represented using the built-in file object.

14.Which data type is used to represent a regular expression in Python?

a. regex
b. re
c. pattern
d. None of the above

Answer: c. pattern

Explanation: In Python, regular expressions are represented using the re.Pattern class.

15.Which data type is used to represent an instance of a class in Python?

a. obj
b. instance
c. self
d. None of the above

Answer: a. obj

Explanation: In Python, an instance of a class is represented using the object data type.

16.Which data type is used to represent a coroutine in Python?

a. coro
b. coroutine
c. yield
d. None of the above

Answer: b. coroutine

Explanation: In Python, a coroutine is represented using the async def statement and the await keyword.

17.Which data type is used to represent a context manager in Python?

a. context
b. contextmanager
c. with
d. None of the above

Answer: b. contextmanager

Explanation: In Python, a context manager is represented using the contextlib.contextmanager decorator.

Data type of Python

18.Which data type is used to represent a frozen set in Python?

a. set
b. frozenset
c. tuple
d. None of the above

Answer: b. frozenset

Explanation: In Python, a frozen set is represented using the built-in frozenset object.

19.Which data type is used to represent a dictionary in Python?

a. dict
b. map
c. set
d. None of the above

Answer: a. dict

Explanation: In Python, a dictionary is represented using the built-in dict object.

20.Which data type is used to represent a named tuple in Python?

a. tuple
b. namedtuple
c. dict
d. None of the above

Answer: b. namedtuple

Explanation: In Python, a named tuple is represented using the collections.namedtuple function.

21.Which data type is used to represent a deque in Python?

a. list
b. deque
c. tuple
d. None of the above

Answer: b. deque

Explanation: In Python, a deque is represented using the collections.deque object.

22.Which data type is used to represent a heap queue in Python?

a. heap
b. queue
c. heapq
d. None of the above

Answer: c. heapq

Explanation: In Python, a heap queue is represented using the heapq module.

23.Which data type is used to represent a stack in Python?

a. stack
b. list
c. queue
d. None of the above

Answer: b. list

Explanation: In Python, a stack can be implemented using a list object.

24.Which data type is used to represent a queue in Python?

a. queue
b. list
c. tuple
d. None of the above

Answer: a. queue

Explanation: In Python, a queue is represented using the queue module.

25.Which data type is used to represent a priority queue in Python?

a. queue
b. heapq
c. deque
d. None of the above

Answer: b. heapq

Explanation: In Python, a priority queue is often implemented using the heapq module.

26.Which data type is used to represent a counter in Python?

a. count
b. counter
c. dict
d. None of the above

Answer: b. counter

Explanation: In Python, a counter is represented using the collections.Counter object.

27.Which data type is used to represent a default dictionary in Python?

a. dict
b. defaultdict
c. counter
d. None of the above

Answer: b. defaultdict

Explanation: In Python, a default dictionary is represented using the collections.defaultdict object.

28.Which data type is used to represent a named dictionary in Python?

a. dict
b. named_dict
c. namedtuple
d. None of the above

Answer: c. namedtuple

Explanation: In Python, a named dictionary can be represented using the collections.namedtuple function.

29.Which data type is used to represent a JSON object in Python?

a. json
b. dict
c. object
d. None of the above

Answer: b. dict

Explanation: In Python, a JSON object is often represented using a dictionary object.

30.Which data type is used to represent a regular expression pattern in Python?

a. regex
b. pattern
c. re
d. None of the above

Answer: c. re

Explanation: In Python, regular expressions are represented using the re module.

31.Which data type is used to represent a date in Python?

a. datetime
b. date
c. time
d. None of the above

Answer: b. date

Explanation: In Python, a date is represented using the datetime.date object.

32.Which data type is used to represent a time in Python?

a. datetime
b. date
c. time
d. None of the above

Answer: c. time

Explanation: In Python, a time is represented using the datetime.time object.

33.Which data type is used to represent a date and time in Python?

a. datetime
b. date
c. time
d. None of the above

Answer: a. datetime

Explanation: In Python, a date and time is represented using the datetime.datetime object.

34.Which data type is used to represent a timedelta in Python?

a. datetime
b. date
c. timedelta
d. None of the above

Answer: c. timedelta

Explanation: In Python, a timedelta is represented using the datetime.timedelta object.

Data type of Python

35.Which data type is used to represent a time zone in Python?

a. timezone
b. tzinfo
c. datetime
d. None of the above

Answer: b. tzinfo

Explanation: In Python, a time zone is represented using the datetime.tzinfo object.

36.Which data type is used to represent a binary data in Python?

a. bytes
b. bytearray
c. binary
d. None of the above

Answer: a. bytes

Explanation: In Python, binary data is represented using the bytes object.

37.Which data type is used to represent a mutable binary data in Python?

a. bytes
b. bytearray
c. binary
d. None of the above

Answer: b. bytearray

Explanation: In Python, mutable binary data is represented using the bytearray object.

38.Which data type is used to represent a memoryview in Python?

a. memoryview
b. bytes
c. bytearray
d. None of the above

Answer: a. memoryview

Explanation: In Python, a memoryview is represented using the memoryview object.

39.Which data type is used to represent a complex number in Python?

a. complex
b. imaginary
c. float
d. None of the above

Answer: a. complex

Explanation: In Python, a complex number is represented using the complex object.

40.Which data type is used to represent a boolean value in Python?

a. boolean
b. bool
c. bit
d. None of the above

Answer: b. bool

Explanation: In Python, a boolean value is represented using the bool object.

41.Which data type is used to represent an ellipsis object in Python?

a. ellipsis
b. …
c. None
d. None of the above

Answer: b. …

Explanation: In Python, an ellipsis object is represented using the … syntax.

42.Which data type is used to represent a module in Python?

a. module
b. package
c. class
d. None of the above

Answer: a. module

Explanation: In Python, a module is represented using a file with a .py extension.

43.Which data type is used to represent a class in Python?

a. module
b. package
c. class
d. None of the above

Answer: c. class

Explanation: In Python, a class is a blueprint for creating objects, and it is represented using the class keyword.

44.Which data type is used to represent a method in Python?

a. method
b. function
c. object
d. None of the above

Answer: a. method

Explanation: In Python, a method is a function that is defined inside a class and is called on an instance of that class.

45.Which data type is used to represent a function in Python?

a. method
b. function
c. object
d. None of the above

Answer: b. function

Explanation: In Python, a function is a block of code that performs a specific task and is defined using the def keyword.

46.Which data type is used to represent a generator in Python?

a. generator
b. iterator
c. list
d. None of the above

Answer: a. generator

Explanation: In Python, a generator is a special type of function that produces a sequence of values using the yield keyword.

47.Which data type is used to represent an iterator in Python?

a. generator
b. iterator
c. list
d. None of the above

Answer: b. iterator

Explanation: In Python, an iterator is an object that can be iterated (looped) upon, returning one value at a time using the next() method.

48.Which data type is used to represent a set in Python?

a. set
b. list
c. tuple
d. None of the above

Answer: a. set

Explanation: In Python, a set is an unordered collection of unique elements, and it is represented using the set object.

49.Which data type is used to represent a frozenset in Python?

a. set
b. frozenset
c. tuple
d. None of the above

Answer: b. frozenset

Explanation: In Python, a frozenset is an immutable set, and it is represented using the frozenset object.