Header Ads Widget

Introduction to Python

Introduction to Python Class


Q1. Which of the following is not in Python Character Set.

a. Letters : A-Z or a – z

b. Digits : 0 – 9

c. Whitespaces : blank space, tab etc

d. Images : Vector

Ans. d. Images : Vector

Q2. Which of the following is not the mode of interacting with python?

a. Interactive Mode

b. Script Mode

c. Hybrid Mode

d. None of the above

Ans. c. Hybrid Mode

Q3. Python supports dynamic typing.

a. True

b. False

Ans. a. True

Q4. What will be the data type of the following variable?

A = ‘101’

a. Integer

b. String

c. Float

d. None of the above

Ans. b. String

Q5. Write the output of the following:

print(range(0,8,2))

a. 0,2,4,6

b. range(0, 8, 2)

c. Error

d. None of the above

Ans. b. range(0, 8, 2)

Q6. Which of the following is not correct about python?

a. Python is an open source language.

b. Python is based on ABC language.

c. Python is developed by Guido Van Rossum

d. None of the above

Ans. d. None of the above

Q7. Smallest element of of python coding is called __________

a. Identifiers

b. Token

c. Keywords

d. Delimiters

Ans. b. Token

Q8. Which of the following is not a token?

a. //

b. “X”

c. ##

d. 23

Ans. c. ##

Q9. Write the output of the following code:

x=2
x=5
x=x+x
print(x)

a. 7

b. 4

c. 10

d. Error

Ans. c. 10

Q10. Write the output of the following code :

x=2
y=3
x+y+5
print(x+y)

a. 10

b. 5

c. Error

d. None of the above

Ans. b. 5

Q11. Which of the following symbol is used to write comment?

a. ?

b. //

c. #

d. **

Ans. c. #

Q12. Writing comments is mandatory in python programs(T/F)

a. True

b. False

Ans. b. False

Q13. Each statement in python is terminated by ___________

a. Semicolon(;)

b. Colon(:)

c. Comma(,)

d. None of the above

Ans. d. None of the above

Q14. Write the output of the following:

print(‘Hello, world!’);print(“H”)

a. Hello world H

b. Hello worldH

c. Hello world
H

d. Error

Ans. c. Hello world
H

Q15. _______ spaces should be left for indentation.

a. 3

b. 4

c. 5

d. 0

Ans. b. 4

Q16. What type of error is returned by the following statement?

def abc(a):
print(a)

a. ErrorIndentation

b. IndentationError

c. SpaceError

d. No error in the given statement

Ans. b. IndentationError

Q17. return statement is mandatory in function definition.(T/F)

a. True

b. False

Ans. b. False

Q18. Which keyword is used to define a function in python?

a. def

b. define

c. new

d. None of the above

Ans. a. def

Q19. Write the output of the following:

a=8
def abc(a):
      print(a)
abc(7)

a. 8

b. Error

c. No Output

d. 7

Ans. d. 7

Q20. Statement below “function definition” begin with spaces called _________________

a. Indentation

b. Condition

c. Definition

d. None of the above

Ans. a. Indentation

Q21. Which of the following is invalid variable name?

a. Sum1

b. Num_1

c. Num 1

d. N1

Ans. c. Num 1

Q22. Write the output of the following.

def abc():
     print("abc")

a. abc

b. Error

c. 0

d. No Output

Ans. d. No Output

Q23. Python is case sensitive.(T/F)

a. True

b. False

Ans. a. True

Q24. Which statement will display square of number (n)

a. print(n * n)

b. print(math.pow(n,2)) # math module is already imported

c. All of the above

d. Only First

Ans. c. All of the above

Q25. What type of error is returned by the following statement?

print(eval(13))

a. SyntaxError

b. TypeError

c. ValueError

d. No Error in this statement

Ans. b. TypeError

Q26. Which statement is adding remainder of 8 divided by 3 to the product of 5 and 6?

a. 8 % 3 + 5 * 6

b. 8/3 + 5 * 6

c. 8 // 3 + 6.5

d. None of the above

Ans. a. 8 % 3 + 5 * 6

Q27. Is a,b = 6 statement will return an error.(T/F)

a. True

b. False

Ans. a. True

Q28. Identify the invalid identifier.

a. Keyword

b. token

c. operator

d. and

Ans. d. and

Q29. Both the print statement will return same output (T/F)

a=9
b=a
print(id(a))
print(id(b))

a. False

b. True

Ans. b. True

Q30. Which keyboard key is used to run python programs?

a. F6

b. F5

c. F + n

d. Ctrl + r

Ans. b. F5

Q31. Which method is used to find the memory location of variable?

a. id( )

b. add( )

c. type( )

d. None of the above

Ans. a. id( )

Q32. ________________ method is used to find the data type of a variable.

a. type( )

b. dtype( )

c. typed( )

d. None of the above

Ans. a. type( )

Q33. _______________ escape sequence is used for horizontal tab.

a. \n

b. \t

c. \T

d. No

Ans. b. \t

Q34. An escape sequence is represented by __________ slash followed by one or two characters.

a. back

b. forward

c. double

d. None of the above

Ans. a. back

Q35. Write the output of the following code :

>>> x = 4 - 7j
>>> print(x.imag, x.real)

a. 4.0 -7.0

b. -7.0 4.0

c. Error

d. None of the above

Ans. b. -7.0 4.0

Q36. Write the output of the following code :

>>> a=9
>>> x=str(a)
>>> b=5
>>> y=str(b)
>>> x+y

a. 14

b. 9,5

c. 95

d. None of the above

Ans. c. 95

Q37. Write the output of the following code :

>>> 7+2//1**2 > 5+2**2//3

a. True

b. False

c. Error

d. None of the above

Ans. a. True

Q38. Write the output of the following code :

>>> s = None
>>> s

a. Nothing will be printed

b. None

c. Shows Error

d. None of the above

Ans. a. Nothing will be printed

Q39. Which of the following assignment will return error?

a. a = b = c = 89

b. a = 6, b = 8

c. a, b, c = 1, 2, 3

d. None of the above

Ans. b. a = 6, b = 8

Q40. Which of the following is wrong in reference to naming of variable?

a. Keywords are not allowed for variable names.

b. Spaces are not allowed for variable names.

c. Variable names can start from number.

d. Special symbols are not allowed

Ans. c. Variable names can start from number.

Q41. Which of the following is invalid identifier?

a. _

b. _1st

c. 1stName

d. While

Ans. c. 1stName

Q42. Identifier name can be of maximum ____________ character

a. 63

b. 79

c. 53

d. any number of

Ans. a. 63

Q43. Which of the following can not be used as an identifier?

a. eval

b. max

c. pass

d. All of the above

Ans. c. pass

Q44. All keywords in Python are in lower case(T/F).

a. True

b. False

Ans. b. False

Q45. Which of the following statement is calculating x raise to power n?

a. x * n

b. x ** n

c. n ** x

d. x ^ n

Ans. b. x ** n

Q46. Write the output of the following.

m, n, p = 1, 2, 3
print(m, n, p)

a. 1, 2, 3

b. 1 2 3

c. Print 1, 2 and 3 vertically

d. Error

Ans. b. 1 2 3

Q47. Which of the following is valid operator?

a. in

b. on

c. it

d. at

Ans. a. in

Q48. Output of print(7 % 21) is ________________

a. 3

b. 7

c. None of the above

d. Error

Ans. b. 7

Q49. Operators of same precedence are executed from _____

a. left to right

b. right to left

c. in any order

d. None of the above

Ans. a. left to right

Q50. Output of print(2 * 3 ** 2) is

a. 16

b. 64

c. 18

d. Error

Ans. c. 18

Q51. Write the output of the following:

x = int(7) + int (‘9’)
print(x)

a. 79

b. 16

c. Error

d. None of the above

Ans. b. 16

Q52. Out of addition(+) and Subtraction (-) operator, which has more precedence?

a. Addition (+)

b. Subtraction (-)

c. Both have same precedence

d. None of the above

Ans. c. Both have same precedence

Q53. Which of the following statement will return error when x = 7 ?

a. print(x)

b. print(int(x))

c. print(eval(x))

d. None of the above

Ans. c. print(eval(x))

Q54. Which of the following store data in pair?

a. List

b. Tuple

c. String

d. Dictionary

Ans. d. Dictionary

Q55. What is the return type of function id( )?

a. float

b. string

c. int

d. None of the above

Ans. c. int

Q56. An ordered set of instructions to be executed by a computer to carry out a specific task is called _______

a. Algorithm

b. Pseudocode

c. Program

d. None of the above

Ans. c. Program

Q57. Computers understand the language of 0s and 1s which is called _______

a. Machine Language

b. Low level Language

c. Binary Language

d. All of the above

Ans. d. All of the above

Q58. A program written in a high-level language is called _________ code

a. Object

b. Source

c. Machine

d. None of the above

Ans. b. Source

Q59. Python uses ____ to convert its instructions into machine language.

a. Interpreter

b. Compiler

c. Both of the above

d. None of the above

Ans. a. Interpreter

Q60. Language translator convert ______________ code to _______________ code.

a. Source, Object

b. Object, Source

c. Machine , Source

d. None of the above

Ans. a. Source, Object

Q61. Which of the following is not the feature of python language?

a. Python is a proprietary software.

b. Python is not case-sensitive.

c. Python uses brackets for blocks and nested blocks.

d. All of the above

Ans. d. All of the above

Q62. In which of the following mode, the interpreter executes the statement and displays the result as soon as we press ‘Enter’ key?

a. Interactive mode

b. Script mode

c. Hybrid mode

d. None of the above

Ans. a. Interactive mode

Q63. By default, the Python scripts are saved with ____________ extension.

a. .pyp

b. .pys

c. .py

d. None of the above

Ans. c. .py

Q64. By default, the Python scripts are saved in ____

a. Document

b. Desktop

c. Python installation folder

d. D drive

Ans. c. Python installation folder

Q65. ________ are reserved words.

a. Keywords

b. Identifiers

c. Variables

d. Comments

Ans. a. Keywords

Q66. Which of the following is not correct for naming an identifier in Python?

a. Identifier can be of any length

b. Identifier should not be a keyword

c. We cannot use special symbols like !, @, #, $, %, etc., in identifiers

d. Spaces are allowed in identifiers

Ans. d. Spaces are allowed in identifiers

Q67. Comments in python program are ________________ by interpreter

a. executed

b. not executed

c. given

d. shared

Ans. b. not executed

Q68. In Python single line comment starts with _________

a. %

b. /*

c. !

d. #

Ans. d. #

Q69. In Python multi line comment starts with ____________

a. %

b. /*

c. !

d. #

Ans. b. /*

Q70. Which of the following is a sequence data type?

a. String

b. Integer

c. Float

d. Dictionary

Ans. a. String

Q71. ___________ is a set of valid characters that a language can recognize.

a. Identifier

b. Token

c. Character set

d. Character group

Ans. c. Character set

Q72. The smallest individual unit in a program is known as _______

a. Token

b. Punctuators

c. Literals

d. Operators

Ans. a. Token

Q73. Which of the following is invalid Identifier?

a. break

b. FILE34

c. F_L

d. Myname

Ans. a. break

Q74. Which of the following is token in Python?

a. Punctuators

b. Literals

c. Keywords

d. All of the above

Ans. d. All of the above

Q75. Which of the following statement is wrong?

a. Literals are data items that have fixed value.

b. Keywords can not be used as identifier.

c. Identifier can start with number.

d. None of the above

Ans. c. Identifier can start with number.

Q76. Which of the following is String literal?

a. “ABC”

b. “123”

c. Both of the above

d. None of the above

Ans. c. Both of the above

Q77. Variables of data types like integers, float etc., hold __

a. single value

b. multiple values

c. exact 2 values

d. None of the above

Ans. a. single value

Q78. Which of the following is invalid data type in python?

a. List

b. String

c. tuple

d. values

Ans. d. values

Q79. Multiline string in python can be created by enclosing text in ____

a. Single quotes(‘ ‘)

b. Double quotes(” “)

c. Triple quotes(”’ ”’)

d. All of the above

Ans. c. Triple quotes(”’ ”’)

Q80. Which of the following is mapping data type in Python?

a. String

b. List

c. Dictionary

d. Tuple

Ans. c. Dictionary

Q81. Variables whose values can be changed after they are created and assigned are called __________________

a. mutable

b. immutable

c. changeable

d. None of the above

Ans. a. mutable

Q82. An _______________ is a symbol which is used to perform specific mathematical or logical operation on values.

a. Operand

b. Operator

c. Keyword

d. Identifier

Ans. b. Operator

Q83. Operators work on values called __________

a. Operating

b. Operand

c. data value

d. Opvalue

Ans. b. Operand

Q84. Which of the following operator is used for integer division?

a. /

b. //

c. \\

d. \

Ans. b. //

Q85. Which operator returns remainder?

a. /

b. //

c. %

d. \\

Ans. c. %

Q86. Which of the following is an exponent operator?

a. *

b. /

c. **

d. ***

Ans. c. **

Q87. Which of the following statement display “RAM” two times?

a. >>> “RAM” + 2

b. >>> “RAM” * 2

c. >>> “RAM” ** 2

d. None of the above

Ans. b. >>> “RAM” * 2

Q88. Write the output of the following:

>>> 7 % 3 ** 3

a. 1

b. 7

c. 3

d. 27

Ans. b. 7

Q89. Which of the following is not an integer literal?

a. 1

b. 7

c. 98

d. “4”

Ans. d. “4”

Q90. Which escape sequence represent newline character?

a. \n

b. \e

c. \t

d. \T

Ans. a. \n

Q91. Which of the following is number data type in python?

a. Integer

b. Complex

c. Boolean

d. All of the above

Ans. d. All of the above

Q92. Which of the following is an invalid relational operator in Python?

a. !=

b. ==

c. >=

d. <>

Ans. d. <>

Q93. print(3 != 4) will evaluates ______

a. True

b. False

c. Error

d. None of the above

Ans. a. True

Q94. Which of the following is an assignment operator?

a. =

b. /=

c. *=

d. All of the above

Ans. d. All of the above

Q95. Statement x += y is equivalent to _____________

a. x = x + y

b. x = x * y

c. y = x + y

d. y = y * x

Ans. a. x = x + y

Q96. Write the output of the following :

>>> num1 = 7
>>> num2 = 3
>>> num1 //= num2
>>> num1

a. 3

b. 7

c. 2

d. 4

Q97. Write the output of the following :

>>> a = 'India'
>>> a *= 3
>>> a

a. ‘IndiaIndiaIndia’

b. ‘India3’

c. ‘3India’

d. None of the above

Q98. Which of the following is invalid logical operator?

a. and

b. or

c. not

d. xor

Ans. d. xor

Q99. print(bool(3 and 6)) evaluates to ______________

a. False

b. True

c. Error

d. None of the above

Ans. b. True

Q100. print(bool(True and True or False)) evaluates to __________

a. False

b. True

c. Error

d. None of the above

Ans. b. True

Q101. >>> bool(0) evaluates to ________________

a. False

b. True

c. Error

d. None of the above

Ans. a. False

Q102. _____________ operators are used to check if a value is a member of the given sequence or not.

a. Logical

b. Identity

c. Membership

d. Relational

Ans. c. Membership

Q103. Write the output of following code:

>>> n1 = 5
>>> n2 = n1
>>> n2 is n1

a. True

b. False

c. Error

d. 5

Ans. a. True

Q104. Which operators can be used to determine whether two variables are referring to the same object or not.

a. Relational

b. Logical

c. Identity

d. Membership

Ans. c. Identity

Q105. Which of the following is valid membership operator?

a. in

b. not in

c. Both of the above

d. None of the above

Ans. c. Both of the above

Q106. ____________ is defined as a combination of constants, variables, and operators.

a. Statement

b. Expression

c. Operation

d. None of the above

Ans. b. Expression

Q107. Which of the following is invalid expression?

a. 250

b. 32 / 4 + 7

c. “Global” + “Citizen”

d. in

Ans. d. in

Q108. Binary operators are operators with ________ operands

a. 1

b. 2

c. 3

d. 4

Ans. b. 2

Q109. >>> 14 + 2 ** 2 evaluates to _________________

a. 256

b. 18

c. 28

d. 32

Ans. b. 18

Q110. >>> 15.0 / 4 + (8 + 3.0) evaluates to ________________

a. 14.75

b. 14

c. 15

d. None of the above

Ans. a. 14.75

Q111. In Python, a ___________ is a unit of code that the Python interpreter can execute

a. expression

b. statement

c. instruction

d. None of the above

Ans. b. statement

Q112. In Python, we have ____________________ function for taking input from the user.

a. input( )

b. accept( )

c. enter( )

d. insert( )

Ans. a. input( )

Q113. The user may enter a number or a string but the input() function treats them as _______

a. integer only

b. list

c. strings only

d. tuple

Ans. c. strings only

Q114. Write the output of the following :

>>> age = input("Enter your age: ")
>>> type(age)

a. <class ‘int’>

b. <class ‘str’>

c. <class ‘list’>

d. None of the above

Ans. b. <class ‘str’>

Q115. Write the output of the following :

>>> age = input("Enter your age: ")
Enter your age: 3
>>> age * 3

a. 9

b. ‘333’

c. ’33’

d. Error

Ans. b. ‘333’

Q116. What type of error is returned by following statement?

>>> age = input("Enter your age: ")
Enter your age: 3
>>> age + 3

a. SyntaxError

b. IndexError

c. ValueError

d. TypeError

Ans. d. TypeError

Q117. Python uses _________________ function to output data to standard output device.

a. print( )

b. display( )

c. output( )

d. none of the above

Ans. a. print( )

Q118. print(“I” + “am” + “in” + “school”) display __________________

a. I am in school

b. I Am In School

c. Iaminschool

d. iaminschool

Ans. c. Iaminschool

Q119. print(“I” , “am” , “in” , “school”) display _________________

a. I am in school

b. I Am In School

c. Iaminschool

d. iaminschool

Q120. Which of the following is parameter of print( ) function?

a. sep

b. end

c. Both of the above

d. None of the above

Ans. c. Both of the above

Q121. int(123.45) is an example of ___________________ .

a. explicit conversion

b. implicit conversion

c. quick conversion

d. None of the above

Ans. a. explicit conversion

Q122. int(20.5 + 2.7) and int(20.5) + int(2.7) will produce the same result.(T/F)

a. True

b. False

Ans. b. False

Q123. ______________ happens when data type conversion is done automatically by Python.

a. Implicit conversion

b. Explicit conversion

c. Both of the above

d. None of the above

Ans. a. Implicit conversion

Q124. Write the output of the following :

num1 = 100 
num2 = 2.0 
sum1 = num1 + num2 
print(sum1)

a. 102

b. 102.0

c. Error

d. None of the above

Ans. b. 102.0

Q125. In given code _____________ conversion takes place.

num1 = 100 
num2 = 2.0 
sum1 = num1 + num2 
print(sum1)

a. implicit

b. explicit

c. hybrid

d. none of the above

Ans. a. implicit

Q126. Which of the following function convert the data type of variable ‘x’ from float to integer?

a. float( )

b. int( )

c. str( )

d. num( )

Ans. b. int( )

Q127. Which of the following is explicit type conversion function in Python?

a. int( )

b. str( )

c. float( )

d. All of the above

Ans. d. All of the above

Q128. Fill in the blank in given code :

print("The total in Rs." + __________(70))

a. int

b. float

c. str

d. bool

Ans. c. str

Q129. In the given code, an integer value stored in variable num1 is added to a float value stored in variable num2, and the result is stored in variable sum1. This is an example of _____

sum1 = num1 + num2

a. implicit conversion

b. explicit conversion

c. data conversion

d. value conversion

Ans. a. implicit conversion

Q130. The process of removing errors from programs is called _______________

a. Programming

b. Documentation

c. Debugging

d. None of the above

Ans. c. Debugging

Q131. Which of the following error may encounter in program of python?

a. Syntax error

b. Logical error

c. Runtime error

d. All of the above

Ans. d. All of the above

Q132. Ravi is writing a program of printing “Hello World” but he forgot to close the bracket of print( ) function (as shown below). What type of error is this?

print("Hello World"

a. Syntax error

b. Logical error

c. Runtime error

d. None of the above

Ans. a. Syntax error

Q133. _________________ produces an undesired output but without termination of the program.

a. Syntax error

b. Logical error

c. Runtime error

d. None of the above

Ans. b. Logical error

Q134. Aman wants to find the average of two numbers 10 and 12 and he write the code as 10 + 12/2, it would run successfully but the output is not correct. What type of error is done by Aman?

a. Syntax error

b. Logical error

c. Runtime error

d. None of the above

Ans. b. Logical error

Q135. ________ error causes abnormal termination of program while it is executing.

a. Syntax error

b. Logical error

c. Runtime error

d. None of the above

Ans. c. Runtime error

Q136. Which of the following statement return run time error ?

a. Divide any number by zero

b. Adding any number to zero

c. Subtracting any number from zero

d. Multiply any number with zero

Ans. a. Divide any number by zero

Q137. Errors in program is also called _________________

a. virus

b. bug

c. beetle

d. val

Ans. b. bug

Q138. IDLE stands for __________

a. Integrated Development LEarning

b. Integrated Development Learning Environment

c. Intelligent Development Learning Environment

d. None of the above

Ans. b. Integrated Development Learning Environment

Q139. Which of the following statement is correct to initialize multiple variables?

a. a = b = c = 85

b. a = b and c = 85

c. a = 85 , c = 85 , b =85

d. All of the above

Ans. a. a = b = c = 85

Q140. Which of the following statement is correct syntactically ?

a. print(“Hello” , sep == ‘@’ , end = ‘ ‘)

b. print(“Hello” , sep = ‘@’ , end = ‘ ‘)

c. Print(“Hello” , sep = ‘@’ , end = ‘ ‘)

d. print(“Hello” , sep = ‘@’ , end = ‘ ‘

Ans. b. print(“Hello” , sep = ‘@’ , end = ‘ ‘)

Q141. Write the output of the following :

print(true and False)

a. True

b. False

c. Error

d. None of the above

Ans. c. Error

Q142. Write the output of the following :

print(3 and (5 or 0))

a. 3

b. 5

c. True

d. False

Ans. b. 5

Q143. Write the output of the following :

print(True and (False or True))

a. True

b. False

c. Error

d. None of the above

Ans. a. True

Q144. Write the output of the following code :

print((15 // 2 ** 2) * 'A')

a. 3

b. Error

c. ‘AAA’

d. 4

Ans. ‘AAA’

Q145. Write the output of the following :

22 + (7 -2 // 9 ** 2)

a. 22

b. 7

c. 29

d. 0

Ans. c. 29

Q146. Which of the following is mutable data type?

a. String

b. Tuple

c. List

d. All of the above

Ans. c. List

Post a Comment

0 Comments