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

What Will Be The Output of The Following Code?: A) 6 B) 8 C) 9 D) 11 B) 8

The document contains a series of questions and answers related to Python programming, covering topics such as file extensions, data types, control structures, and basic syntax. It includes multiple choice questions with correct answers provided for each. Additionally, it touches on concepts related to machine learning and data handling in Python.

Uploaded by

piyush943024
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 views23 pages

What Will Be The Output of The Following Code?: A) 6 B) 8 C) 9 D) 11 B) 8

The document contains a series of questions and answers related to Python programming, covering topics such as file extensions, data types, control structures, and basic syntax. It includes multiple choice questions with correct answers provided for each. Additionally, it touches on concepts related to machine learning and data handling in Python.

Uploaded by

piyush943024
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/ 23

Which of the following is the correct extension of a Python file?

A) .py
B) .python
C) .pt
D) .pyt
Answer: A) .py

1. What is the output of print(type(5)) in Python?


A) <class 'float'>
B) <class 'str'>
C) <class 'int'>
D) <class 'boolean'>
Answer: C) <class 'int'>

What will be the output of the following code?

print(2 ** 3)

A) 6

B) 8

C) 9

D) 11

Answer: B) 8

Which data structure does Python use to store values as key-value pairs?
A) list
B) set
C) dictionary
D) tuple
Answer: C) dictionary

What will be the output of the following code?

my_tuple = (1, 2, 3)
print(my_tuple[1])

A) 1
B) 2
C) 3
D) Error
Answer: B) 2

Which of the following data structures is immutable?


A) List
B) Dictionary
C) Set
D) Tuple
1
Answer: D) Tuple

Who has created the Python?


A. Guido Van Rossum
B. Guido Vein Rasmi
C. Mark Elliot Zuckerberg
D. Jack Patrick Dorsey
ANSWER: A

Which is not the feature of Python?


A. It is interpreted language.
B. It supports block and indentation for statements.
C. It does not support the OOPs Programming.
D. It is a general purpose programming language.
ANSWER: C

_______ is used to define the comments in the program.


A. #
B. ''
C. //
D. $
ANSWER: A

_______ is not a reserve word.


A. import
B. for
C. while
D. unknown
ANSWER: D

Which is a invalid Identifier.


A. MYVAR
B. MY%VAR
C. MY_VAR
D. _MY_VAR
ANSWER: B

How can you check the length of a string s = "Python"?


A) s.size()
B) s.len()
C) length(s)
D) len(s)
Answer: D) len(s)

What will be the output of the following code?

s = "Python"
print(s[1:4])

A) yth
B) Pyt
C) ytho
D) ytho
2
Answer: A) yth

What will be the output of the following code?

my_list = [1, 2, 3]
my_list.append(4)
print(my_list)

A) [1, 2, 3]

B) [1, 2, 3, 4]

C) [1, 4]

D) [1, 2, 3, 3]

Answer: B) [1, 2, 3, 4]

What is the correct file extension for Python files?

a) .pyt
b) .pt
c) .py
d) .python
Answer: c) .py

Which keyword is used to define a function in Python?

a) func
b) define
c) def
d) lambda
Answer: c) def

Which of the following is used to write a comment in Python?

a) //
b) <!--
c) #
d) %
Answer: c) #

How do you create a list in Python?

a) {1, 2, 3}
b) (1, 2, 3)

3
c) [1, 2, 3]
d) <1, 2, 3>
Answer: c) [1, 2, 3]

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

a) my_var
b) 2var
c) var_2
d) _var
Answer: b) 2var

What is the output of the following code?

print("Python" * 2)

a) PythonPython
b) Python2
c) Python Python
d) Error
Answer: a) PythonPython

Which of the following is used to take input from the user in Python?

a) scanf()
b) input()
c) gets()
d) cin
Answer: b) input()

Which is not valid for function.?

A. Function can return a maximum one value.

B. Function with only PASS statement gives error message.

C. Sum%Num is a valid function name.

D. SUM_NUM is a valid function name.

ANSWER: C

Which one is not true for Aggregate Function in Numpy?

A. Sum() – find the sum of array.

B. Min() – Find the minimum of array.


4
C. Argmin() – find the index of minimum from array.

D. Avg() – find the average of the value in array.

ANSWER: A

Which of the following data type is used to store values in Key & Value format?

A. Class

B. List

C. Dictionary

D. Tuple

ANSWER: C

Which of the following has more precedence?

A. +

B. /

C. -

D. ()

ANSWER: D

Which one is not true Creating Matrix?

A. Empty( )- create an array of specified shape and size.

B. Ones( )- create an array filled with ones.

C. Zeros( ) – create an array filled with zeros.

D. NonEmpty()- create an initialized array.

ANSWER: D

What is the correct way to create a dictionary in Python?

a) {key1 = value1, key2 = value2}


b) {key1: value1, key2: value2}
5
c) [key1: value1, key2: value2]
d) (key1 = value1, key2 = value2)
Answer: b) {key1: value1, key2: value2}

What does the len() function do in Python?

a) Returns the length of a string


b) Returns the length of a list
c) Returns the length of any iterable
d) All of the above
Answer: d) All of the above

How do you start a loop in Python?

a) loop()
b) while()
c) for()
d) Both b and c
Answer: d) Both b and c

How do you import a module in Python?

a) import module_name
b) include module_name
c) load module_name
d) use module_name
Answer: a) import module_name

Which of the following is not a Python keyword?

a) lambda
b) pass
c) eval
d) assert
Answer: c) eval

How do you check for equality in Python?

a) =
b) ==
c) !=
d) ===
Answer: b) ==

What does break do in Python loops?

6
a) Exits the current loop
b) Skips the current iteration
c) Exits the program
d) Stops execution of all loops
Answer: a) Exits the current loop

How do you access elements in a dictionary?

a) Using keys
b) Using indexes
c) Using values
d) Using positions
Answer: a) Using keys

What is the default value returned by a function if no return statement is provided?

a) 0
b) None
c) False
d) Error
Answer: b) None

What does the range(5) function return?

a) [1, 2, 3, 4, 5]
b) [0, 1, 2, 3, 4]
c) (0, 1, 2, 3, 4)
d) None
Answer: b) [0, 1, 2, 3, 4]

What is the output of 10 // 3?

a) 3.33
b) 3
c) 4
d) Error
Answer: b) 3

Which of the following data types is immutable?

a) List
b) Dictionary
7
c) Tuple
d) Set
Answer: c) Tuple

What is the purpose of the is operator in Python?

a) Checks equality
b) Checks identity
c) Checks membership
d) Checks type
Answer: b) Checks identity

2. Which method is used to remove whitespace from a string in Python?

a) trim()
b) remove()
c) strip()
d) clear()
Answer: c) strip()

3. How do you handle exceptions in Python?

a) try/except
b) throw/catch
c) error/catch
d) raise/handle
Answer: a) try/except

4. How do you add an element to a list in Python?

a) list.push(element)
b) list.add(element)
c) list.append(element)
d) list.insert(element)
Answer: c) list.append(element)

What is the output of the following code?

print("Hello"[-1])

a) H
b) e
c) o
d) Error
Answer: c) o

Which of the following is used for string formatting in Python?

a) %
b) .format()
8
c) f-strings
d) All of the above
Answer: d) All of the above

What does continue do in Python loops?

a) Exits the current loop


b) Skips the rest of the code in the current iteration
c) Exits the program
d) Stops execution of all loops
Answer: b) Skips the rest of the code in the current iteration

What is the output of the following code?

print("Hello".upper())

a) hello
b) HELLO
c) Hello
d) Error
Answer: b) HELLO

5. Which function is used to convert a string to an integer in Python?

a) int()
b) str()
c) float()
d) eval()
Answer: a) int()

6. Which method is used to add a key-value pair to a dictionary?

a) add()
b) append()
c) insert()
d) update()
Answer: d) update()

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

a) typeof()
b) dataType()
c) type()
d) varType()
Answer: c) type()

8. In machine learning, supervised learning is used when:

9
A) Labels are unknown
B) Labels are known
C) No training data is available
D) The data is unlabeled
Answer: B) Labels are known

9. Which of the following algorithms is an example of unsupervised learning?


A) Decision Tree
B) Linear Regression
C) K-Means Clustering
D) Logistic Regression
Answer: C) K-Means

10. Overfitting occurs when a model:


A) Performs well on both training and test data
B) Performs well on training data but poorly on test data
C) Is too simple to capture the data trends
D) Ignores irrelevant features
Answer: B) Performs well on training data but poorly on test data

11. Which algorithm would be most suitable for detecting spam emails?
A) K-means clustering
B) Naïve Bayes
C) Linear regression
D) None
Answer: B) Naïve Bayes

12. Which of the following is used in supervised learning?


A) Decision Tree
B) K-means
C) Hierarchical clustering
D) None
Answer: A) Decision Tree

Which of the following models is based on Bayes’ Theorem?


A) Decision Tree
B) Logistic Regression
C) Naïve Bayes
D) K-Nearest Neighbors
Answer: C) Naïve Bayes

In reinforcement learning, the agent’s goal is to:

A) Maximize a cumulative reward

B) Minimize a loss function

C) Use supervised data

D) Find a single optimal action


10
Answer: A) Maximize a cumulative reward

Which is an invalid Literal?

A. Test

B. Number

C. Boolean

D. Special

ANSWER: A

Which is an invalid String Literal?

A. "This is Python"

B. "P"

C. 'Sum'

D. #Sum#

ANSWER: D

What is the output for following code: name="Hello World" print(type(name))

A. Hello World

B. hello World

C. <class 'str'>

D. str

ANSWER: C

Which is an invalid data type?

A. List

B. Tuple

C. Array

11
D. String

ANSWER: C

Which is invalid Constant Name?

A. MYVAR

B. MY%VAR

C. MY_VAR

D. _MY_VAR

ANSWER: B

Which is an invalid String ?

A. 'ABC'

B. ''ABC''

C. '''ABC'''

D. ''''ABC''''

ANSWER: D

Which is an invalid in Python ?

A. "This is Python"

B. [ 10 ,20 , ''ABC'' ]

C. ( 10 ,20 , ''ABC'' )

D. - 10 ,20 , ''ABC'' -

ANSWER: D

Which is not true for List Data Type ?

A. Items enclosed in the [ ].

B. Items must be of similar type.

12
C. + sign concatenate the list.

D. * sign repeats the list.

ANSWER: B

Which is not true for Tuple Data Type ?

A. Items enclosed in the [ ].

B. Items can be of any type.

C. Items are read only.

D. * sign repeats the tuple.

ANSWER:C

Which is an invalid Arithmetic Operator?

A. **

B. /

C. //

D. ***

ANSWER: D

Which is an valid Membership Operator?

A. not in

B. not is

C. has

D. none

ANSWER: A

Which is an invalid Bitwise Operator ?

13
A. >>

B. <<

C. >>>

D. ^

ANSWER: C

X=20>>2 is equal to ____________?

A. 5

B. 10

C. 15

D. 0

ANSWER: A

X= 5<<2 is equal to _________ ?

A. 5

B. 10

C. 15

D. 20

ANSWER: D

Which is an invalid branching control structure?

A. if

B. if…else

C. if…else...elif…

D. if…elif…else…

ANSWER: C

14
Which one is not allowed with While Loop?

A. else

B. break

C. continue

D. elif

ANSWER: D

Which is true about the Break statement with While Loop?

A. It skips the remaining body of the loop.

B. It repeats the body of the loop.

C. It is performs nothing.

D. It transfers the flow outside the body of loop.

ANSWER: D

Which is true about the Continue statement with While Loop?

A. It skips the remaining body of the loop, jumps to the beginning.

B. It repeats the body of the loop.

C. It is performs nothing.

D. It transfers the flow outside the body of loop.

ANSWER: A

input( ) function return data type is

A. int

B. float

C. bool

15
D. str

ANSWER: D

Which is not true about the print( ) function?

A. It is an in-built function.

B. It prints the output on screen.

C. Only integer variables or messages are allowed.

D. It apply the new line character at the end.

ANSWER: C

Which one is not allowed with for Loop?

A. else

B. break

C. continue

D. elif

ANSWER: D

Which is true about the Break statement with for Loop?

A. It skips the remaining body of the loop.

B. It repeats the body of the loop.

C. It is performs nothing.

D. It transfers the flow outside the body of loop.

ANSWER: D

Which is true about the Continue statement with for Loop?

A. It skips the remaining body of the loop, jumps to the beginning.

16
B. It repeats the body of the loop.

C. It is performs nothing.

D. It transfers the flow outside the body of loop.

ANSWER: A

for loop not allows to iterate on is

A. int

B. list

C. tuple

D. string

ANSWER: A

Which is not valid for range( ) function.?

A. It generates the sequence of numbers upto STOP value.

B. START value is optional.

C. STEP value is optional.

D. Data type of sequence is ‘RANGE’.

ANSWER: A

Which one is true for nested While Loop?

A. Nested loops not allowed with while loop.

B. Break jumps out of all the loop.

C. Break jumps out of only inner loop.

D. Break allowed with only FOR Loop.

ANSWER: C

17
Which one is true for nested FOR Loop?

A. FOR loop allowed on number data type.

B. FOR loop allowed on string data type.

C. Break not allowed with FOR Loop.

D. Nesting not allowed on FOR Loop.

ANSWER: B

Which of the following method creates a new array object that looks at the same data?

A. view

B. copy

C. paste

D. all of the mentioned

ANSWER: A

Which is not a valid format character for strings.

A. %f

B. %d

C. %u

D. %t

ANSWER: D

Which function is invalid for string.?

A. Strip( ).

B. Lower( ).

C. Split( ).

D. Repeat( ).

18
ANSWER: D

Which of the following statements is used to create an empty set?

A. { }

B. [ ]

C. ( )

D. set( )

ANSWER: D

The ________ function returns its argument with a modified shape, whereas the ________ method
modifies the array itself.

A. reshape, resize

B. resize, reshape

C. reshape2, resize

D. all of the mentioned

ANSWER: A

Which of the following input can be accepted by DataFrame?

A. Structured ndarray

B. Series

C. DataFrame

D. All of the mentioned

ANSWER: D

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

19
A. print(t[3])

B. t[3] = 45

C. print(max(t))

D. print(len(t))

ANSWER: B

If a=(1,2,3,4), a[1:-1] is _________

A. Error, tuple slicing doesn’t exist

B. [2,3]

C. (2,3,4)

D. (2,3)

ANSWER: B

Which one is not true for Dictionary ?

A. Items are in (key : value) pair.

B. Items are immutable.

C. Values must be unique.

D. Key can be number or string.

ANSWER: C

Which is not valid for Array Split and join?

A. hstack( )- joins arrays horizontally.

B. hsplit( ) – splits arrays horizontally.

C. array_split( ) – split the array into based on count.

D. concatenate( ) - joins arrays horizontally only.

ANSWER: D

20
Which one is not true for Dictionary?

A. d1=d2 allows to copy the one dictionary items to other, with reference.

B. d1=d2 allows to copy the one dictionary items to other, without reference.

C. copy( ) method allows to copy the one dictionary items to other, without reference.

D. dict( ) method allows to copy the one dictionary items to other, without reference.

ANSWER: A

Which predefined Python function is used to find length of string?

A. length()

B. len()

C. strlen()

D. stringlength()

ANSWER: B

Which one is used for visualization of data?

A. numpy libraries.

B. pandas libraries.

C. tkinter libraries.

D. matplotlib libraries.

ANSWER: D

Which of the following is NOT supervised learning?

A. PCA

B. Decision Tree

21
C. Linear Regression

D. Naive Bayesian

ANSWER: A

How do you handle missing or corrupted data in a dataset?

A.Drop missing rows or columns

B.Replace missing values with mean/median/mode

C.Assign a unique category to missing values

D.All of the these

ANSWER:D

In a regression and correlation analysis if r 2 = 1, then

A. SSE = SST

B. SSE = 1

C. SSR = SSE

D. SSR = SST

ANSWER:D

In regression analysis, the variable that is being predicted is the

A. response, or dependent, variable

B. independent variable

C. intervening variable

D. is usually x

ANSWER:A

What is Machine learning?

22
A. The autonomous acquisition of knowledge through the use of computer programs

B.The autonomous acquisition of knowledge through the use of manual programs

C.The selective acquisition of knowledge through the use of computer programs

D. The selective acquisition of knowledge through the use of manual programs

ANSWER:A

13. In clustering, the “elbow method” is used to determine:

 A) Optimal number of clusters


 B) Cluster quality
 C) Cluster centroids
 D) Model parameters

Answer: A) Optimal number of clusters

The perceptron algorithm is:

 A) A type of supervised learning


 B) An unsupervised algorithm
 C) A clustering technique
 D) A deep learning algorithm
 Answer: A) A type of supervised learning

14. In decision trees, entropy is used to measure:

 A) Model accuracy
 B) The randomness in the data
 C) The depth of the tree
 D) The number of nodes
 Answer: B) The randomness in the data

In a decision tree, which metric is commonly used to split nodes in classification problems?
A) Entropy
B) Gradient
C) Learning Rate
D) Euclidean Distance
Answer: A) Entropy

23

You might also like