[go: up one dir, main page]

0% found this document useful (0 votes)
190 views11 pages

Hahahaha Python Questions - Variable Names

This document contains multiple choice questions about Python variable names, basic operators, core data types, numeric types, and precedence and associativity. It includes 10 questions in each section testing knowledge of Python syntax rules, valid and invalid variable names, operator precedence, and core data type properties like lists, tuples, and dictionaries.

Uploaded by

Quinone Quentin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
190 views11 pages

Hahahaha Python Questions - Variable Names

This document contains multiple choice questions about Python variable names, basic operators, core data types, numeric types, and precedence and associativity. It includes 10 questions in each section testing knowledge of Python syntax rules, valid and invalid variable names, operator precedence, and core data type properties like lists, tuples, and dictionaries.

Uploaded by

Quinone Quentin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Hahahaha

Python Questions– Variable Names


This set of Python Multiple Choice Questions (MCQs) focuses on “variable Names”.

1. Is Python case sensitive when dealing with identifiers?


a) yes
b) no
c) machine dependent
d) none of the mentioned

2. What is the maximum possible length of an identifier?


a) 31 characters
b) 63 characters
c) 79 characters
d) none of the mentioned

3. Which of the following is invalid?


a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned

4. Which of the following is an invalid variable?


a) my_string_1
b) 1st_string
c) foo
d) _

5. Why are local variable names beginning with an underscore discouraged?


a) they are used to indicate a private variables of a class
b) they confuse the interpreter
c) they are used to indicate global variables
d) they slow down execution

6. Which of the following is not a keyword?


a) eval
b) assert
c) nonlocal
d) pass

7. All keywords in Python are in


a) lower case
b) UPPER CASE
c) Capitalized
d) None of the mentioned

8. Which of the following is true for variable names in Python?


a) unlimited length
b) all private members must have leading and trailing underscores
c) underscore and ampersand are the only two special characters allowed
d) none of the mentioned

9. Which of the following is an invalid statement?


a) abc = 1,000,000
b) a b c = 1000 2000 3000
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000

10. Which of the following cannot be a variable?


a) __init__
b) in
c) it
d) on

Python Questions and Answers – Basic Operators


This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Basic
Operators”.

1. Which is the correct operator for power(xy)?


a) X^y
b) X**y
c) X^^y
d) None of the mentioned

2. Which one of these is floor division?


a) /
b) //
c) %
d) None of the mentioned

3. What is the order of precedence in python?


i) Parentheses
ii) Exponential
iii) Multiplication
iv) Division
v) Addition
vi) Subtraction

a) i,ii,iii,iv,v,vi
b) ii,i,iii,iv,v,vi
c) ii,i,iv,iii,v,vi
d) i,ii,iii,iv,vi,v

4. What is the answer to this expression, 22 % 3 is?


a) 7
b) 1
c) 0
d) 5

5. Mathematical operations can be performed on a string. State whether true or false.


a) True
b) False

6. Operators with the same precedence are evaluated in which manner?


a) Left to Right
b) Right to Left
c) Can’t say
d) None of the mentioned

7. What is the output of this expression, 3*1**3?


a) 27
b) 9
c) 3
d) 1

8. Which one of the following has the same precedence level?


a) Addition and Subtraction
b) Multiplication, Division and Addition
c) Multiplication, Division, Addition and Subtraction
d) Addition and Multiplication

9. The expression Int(x) implies that the variable x is converted to integer. State whether true
or false.
a) True
b) False

10. Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
Python Questions and Answers – Core Data types
This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Core Data
Types”.

1. Which of these in not a core data type?


a) Lists
b) Dictionary
c) Tuples
d) Class

2. Given a function that does not return any value, What value is thrown by default when
executed in shell.
a) int
b) bool
c) void
d) None

3. Following set of commands are executed in shell, what will be the output?

>>>str="hello"
>>>str[:2]
>>>
a) he
b) lo
c) olleh
d) hello

4. Which of the following will run without errors ?


a) round(45.8)
b) round(6352.898,2,5)
c) round()
d) round(7463.123,2,1)

.
5. What is the return type of function id?
a) int
b) float
c) bool
d) dict

6. In python we do not specify types,it is directly interpreted by the compiler, so consider the
following operation to be performed.
>>>x = 13 ? 2
objective is to make sure x has a integer value, select all that apply (python 3.xx)
a) x = 13 // 2
b) x = int(13 / 2)
c) x = 13 % 2
d) All of the mentioned

7. What error occurs when you execute?


apple = mango
a) SyntaxError
b) NameError
c) ValueError
d) TypeError

8. Carefully observe the code and give the answer.

def example(a):
a = a + '2'
a = a*2
return a
>>>example("hello")
a) indentation Error
b) cannot perform mathematical operation on strings
c) hello2
d) hello2hello2

9. What data type is the object below ?


L = [1, 23, ‘hello’, 1].
a) list
b) dictionary
c) array
d) tuple

10. In order to store values in terms of key and value we use what core data type.
a) list
b) tuple
c) class
d) dictionary

11. Which of the following results in a SyntaxError ?


a) ‘”Once upon a time…”, she said.’
b) “He said, ‘Yes!'”
c) ‘3\’
d) ”’That’s okay”’

12. The following is displayed by a print function call:


tom
dick
harry
Select all of the function calls that result in this output
a) print(”’tom
\ndick
\nharry”’)
b) print(”’tomdickharry”’)
c) print(‘tom\ndick\nharry’)
d) print(‘tom
dick
harry’)

13. What is the average value of the code that is executed below ?

>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
a) 85.0
b) 85.1
c) 95.0
d) 95.1

14. Select all options that print


hello-how-are-you
a) print(‘hello’, ‘how’, ‘are’, ‘you’)
b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
c) print(‘hello-‘ + ‘how-are-you’)
d) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’)

15. What is the return value of trunc() ?


a) int
b) bool
c) float
d) None

Python Questions and Answers – Numeric Types


This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Numeric
Types”.

1. What is the output of print 0.1 + 0.2 == 0.3?


a) True
b) False
c) Machine dependent
d) Error

2. Which of the following is not a complex number?


a) k = 2 + 3j
b) k = complex(2, 3)
c) k = 2 + 3l
d) k = 2 + 3J

3. What is the type of inf?


a) Boolean
b) Integer
c) Float
d) Complex

4. What does ~4 evaluate to?


a) -5
b) -4
c) -3
d) +3

5. What does ~~~~~~5 evaluate to?


a) +5
b) -11
c) +11
d) -5

6. Which of the following is incorrect?


a) x = 0b101
b) x = 0x4f5
c) x = 19023
d) x = 03964

7. What is the result of cmp(3, 1)?


a) 1
b) 0
c) True
d) False

8.
. Which of the following is incorrect?
a) float(‘inf’)
b) float(‘nan’)
c) float(’56’+’78’)
d) float(’12+34′)

9. What is the result of round(0.5) – round(-0.5)?


a) 1.0
b) 2.0
c) 0.0
d) None of the mentioned
10. What does 3 ^ 4 evaluate to?
a) 81
b) 12
c) 0.75
d) 7
Python Questions and Answers – Precedence and Associativity – 1
This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Precedence
and Associativity – 1”.

1. The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same. State whether true or
false.
a) True
b) False

2. The value of the expression:


4+3%5
a) 4
b) 7
c) 2
d) 0

3. Evaluate the expression given below if A= 16 and B = 15.

A % B // A
a) 0.0
b) 0
c) 1.0
d) 1

4. Which of the following operators has its associativity from right to left?
a) +
b) //
c) %
d) **

5. What is the value of x if:

x = int(43.55+2/2)
a) 43
b) 44
c) 22
d) 23

6. What is the value of the following expression?

2+4.00, 2**4.0
a) (6.0, 16.0)
b) (6.00, 16.00)
c) (6, 16)
d) (6.00, 16.0)

7. Which of the following is the truncation division operator?


a) /
b) %
c) //
d) |

8. What are the values of the following expressions:

2**(3**2)
(2**3)**2
2**3**2
a) 64, 512, 64
b) 64, 64, 64
c) 512, 512, 512
d) 512, 64, 512

9. What is the value of the following expression:

8/4/2, 8/(4/2)
a) (1.0, 4.0)
b) (1.0, 1.0)
c) (4.0. 1.0)
d) (4.0, 4.0)

10. What is the value of the following expression:

float(22//3+3/3)
a) 8
b) 8.0
c) 8.3
d) 8.33

Python Questions and Answers – Precedence and Associativity – 2


This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Precedence
and Associativity – 2”.

1. What is the output of the following expression:

print(4.00/(2.0+2.0))
a) Error
b) 1.0
c) 1.00
d) 1

2. Consider the expression given below. The value of X is:

X = 2+9*((3*12)-8)/10
a) 30.0
b) 30.8
c) 28.4
d) 27.2

3. Which of the following expressions involves coercion when evaluated in Python?


a) 4.7 – 1.5
b) 7.9 * 6.3
c) 1.7 % 2
d) 3.4 + 4.6

4. What is the value of the following expression:

24//6%3, 24//4//2
a) (1,3)
b) (0,3)
c) (1,0)
d) (3,1)

5. Which among the following list of operators has the highest precedence?

+, -, **, %, /, <<, >>, |


a) <<, >>
b) **
c) |
d) %

6. What is the value of the expression:

float(4+int(2.39)%2)
a) 5.0
b) 5
c) 4.0
d) 4

7. Which of the following expressions is an example of type conversion?


a) 4.0 + float(3)
b) 5.3 + 6.3
c) 5.0 + 3
d) 3 + 7

8. Which of the following expressions results in an error?


a) float(‘10’)
b) int(‘10’)
c) float(’10.8’)
d) int(’10.8’)

9. What is the value of the expression:

4+2**5//10
a) 3
b) 7
c) 77
d) 0

10. The expression 2**2**3 is evaluates as: (2**2)**3. State whether this statement is true or
false.
a) True
b) False

Syke boiiiiiiiiiiiiiiiiiiiii

You might also like