Solved MCQs on Python

CORE DATATYPES 1. Which of these in not a core datatype? a) Lists b) Dictionary c) Tuples d) Class View Answer Answer:d Explan...



CORE DATATYPES

1. Which of these in not a core datatype?
a) Lists
b) Dictionary
c) Tuples
d) Class
View Answer
Answer:d
Explanation:Class is a user defined datatype.
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
View Answer
Answer:d
Explanation:Python shell throws a NoneType object back.
3. Following set of commands are executed in shell, what will be the output?
  1. >>>str="hello"
  2. >>>str[:2]
  3. >>>
a) he
b) lo
c) olleh
d) hello
View Answer
Answer:a
Explanation:We are printing only the 1st two bytes of string and hence the answer is “he”.
4. Which of the following will run without errors(multiple answers possible) ?
a) round(45.8)
b) round(6352.898,2)
c) round()
d) round(7463.123,2,1)
View Answer
Answer:a,b
Explanation:Execute help(round) in the shell to get details of the parameters that are passed into the round function.
5. What is the return type of function id ?
a) int
b) float
c) bool
d) dict
View Answer
Answer:a
Explanation:Execute help(id) to find out details in python shell.id returns a integer value that is unique.
6. In python we do not specify types,it is directly interpreted by the compiler, so consider the following operation to be performed.
  1. >>>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) x = 13 % 2
View Answer
Answer:a,b,d
Explanation:// is integer operation in python 3.0 and int(..) is a type cast operator.
7. What error occurs when you execute?
apple = mango
a) SyntaxError
b) NameError
c) ValueError
d) TypeError
View Answer
Answer:b
Explanation:Mango is not defined hence name error.
8. Carefully observe the code and give the answer.
  1. def example(a):
  2.     a = a + '2'
  3.      a = a*2
  4.     return a
  5. >>>example("hello")
a) indentation Error
b) cannot perform mathematical operation on strings
c) hello2
d) hello2hello2
View Answer
Answer:a
Explanation:Python codes have to be indented properly.
9. What dataype is the object below ?
L = [1, 23, ‘hello’, 1] a) List
b) dictionary
c) array
d) tuple
View Answer
Answer:a
Explanation:List datatype can store any values within it.
10. In order to store values in terms of key and value we use what core datatype.
a) List
b) tuple
c) class
d) dictionary
View Answer
Answer:d
Explanation:Dictionary stores values in terms of keys and values.
11. Which of the following results in a SyntaxError(Multiple answers possible) ?
a) ‘”Once upon a time…”, she said.’
b) “He said, “Yes!””
c) ‘3\’
d) ”’That’s okay”’
View Answer
Answer:b,c
Explanation:Carefully look at the colons.
12. The following is displayed by a print function call:
  1. tom
  2. dick
  3. harry
Select all of the function calls that result in this output
a) print(”’tom
\ndick
\nharry”’)
b) print(”’tom
dick
harry”’)
c) print(‘tom\ndick\nharry’)
d) print(‘tom
dick
harry’)
View Answer
Answer:b,c
Explanation:The \n adds a new line.
13. What is the average value of the code that is executed below ?
  1. >>>grade1 = 80
  2. >>>grade2 = 90
  3. >>>average = (grade1 + grade2) / 2
a) 85
b) 85.0
c) 95
d) 95.0
View Answer
Answer:b
Explanation:Cause a decimal value to appear as output.
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’)
View Answer
Answer:c,d
Explanation:Execute in the shell.
15. What is the return value of trunc() ?
a) int
b) bool
c) float
d) None
View Answer
Answer:a
Explanation:Executle help(math.trunc) to get details.

BASIC OPERATORS
1. Which is the correct operator for power(x^y)?
a) X^y
b) X**y
c) X^^y
d) None of the mentioned
View Answer
Answer: b
Explanation: In python, power operator is x**y i.e. 2**3=8.
2. Which one of these is floor division?
a) /
b) //
c) %
d) None of the mentioned
View Answer
Answer: b
Explanation: When both of the operands are integer then python chops out the fraction part and gives you the round off value, to get the accurate answer use floor division. This is floor division. For ex, 5/2 = 2.5 but both of the operands are integer so answer of this expression in python is 2.To get the 2.5 answer, use floor division.
3. What is the order of precedence in python?
i) Parentheses
ii) Exponential
iii) Division
iv) Multiplication
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
View Answer
Answer: a
Explanation: For order of precedence, just remember this PEDMAS (similar to BODMAS)
4. What is answer of this expression, 22 % 3 is?
a) 7
b) 1
c) 0
d) 5
View Answer
Answer: b
Explanation: Modulus operator gives remainder. So, 22%3 gives the remainder, that is, 1.
5. Mathematical operations can be performed on a string. State whether true or false.
a) True
b) False
View Answer
Answer: b
Explanation: You can’t perform mathematical operation on string even if the string is in the form: ‘1234…’.
6. Operators with the same precedence are evaluated in which manner?
a) Left to Right
b) Right to Left
View Answer
Answer: a
Explanation: None.
7. What is the output of this expression, 3*1**3?
a) 27
b) 9
c) 3
d) 1
View Answer
Answer: c
Explanation: First this expression will solve 1**3 because exponential have higher precedence than multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.
8. Which one of the following have the same precedence?
a) Addition and Subtraction
b) Multiplication and Division
c) a and b
d) None of the mentioned
View Answer
Answer: c
Explanation: None.
9. The expression Int(x) implies that the variable x is converted to integer. State whether true or false.
a) True
b) False
View Answer
Answer: a
Explanation: None.
10. Which one of the following have the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
View Answer
Answer: d
Explanation: Just remember: PEDMAS, that is, Parenthesis, Exponentiation, Division, Multiplication, Addition, Subtraction. Note that the precedence order of Division and Multiplication is the same. Likewise, the order of Addition and Subtraction is also the same.
VARIABLE NAMES
1. Is Python case sensitive when dealing with identifiers?
a) yes
b) no
c) machine dependent
d) none of the mentioned
View Answer
Answer: a
Explanation: Case is always significant.
2. What is the maximum possible length of an identifier?
a) 31 characters
b) 63 characters
c) 79 characters
d) none of the mentioned
View Answer
Answer: d
Explanation: Identifiers can be of any length.
3. Which of the following is invalid?
a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned
View Answer
Answer: d
Explanation: All the statements will execute successfully but at the cost of reduced readability.
4. Which of the following is an invalid variable?
a) my_string_1
b) 1st_string
c) foo
d) _
View Answer
Answer: b
Explanation: Variable names should not start with a number.
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
View Answer
Answer: a
Explanation: As Python has no concept of private variables, leading underscores are used to indicate variables that must not be accessed from outside the class.
6. Which of the following is not a keyword?
a) eval
b) assert
c) nonlocal
d) pass
View Answer
Answer: a
Explanation: eval can be used as a variable.
7. All keywords in Python are in
a) lower case
b) UPPER CASE
c) Capitalized
d) none
View Answer
Answer: d
Explanation: True, False and None are capitalized while the others are in lower case.
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
View Answer
Answer: a
Explanation: Variable names can be of any length.
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
View Answer
Answer: b
Explanation: Spaces are not allowed in variable names.
10. Which of the following cannot be a variable?
a) __init__
b) in
c) it
d) on
View Answer
Answer: b
Explanation: in is a keyword.

REGULAR EXPRESSIONS
1. Which module in Python supports regular expressions?
a) re
b) regex
c) pyregex
d) none of the mentioned
View Answer
Answer: a
Explanation: re is a part of the standard library and can be imported using: import re.
2. Which of the following creates a pattern object?
a) re.create(str)
b) re.regex(str)
c) re.compile(str)
d) re.assemble(str)
View Answer
Answer: c
Explanation: It converts a given string into a pattern object.
3. What does the function re.match do?
a) matches a pattern at the start of the string
b) matches a pattern at any position in the string
c) such a function does not exist
d) none of the mentioned
View Answer
Answer: a
Explanation: It will look for the pattern at the beginning and return None if it isn’t found.
4. What does the function re.search do?
a) matches a pattern at the start of the string
b) matches a pattern at any position in the string
c) such a function does not exist
d) none of the mentioned
View Answer
Answer: b
Explanation: It will look for the pattern at any position in the string.
5. What is the output of the following?
sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print(matched.groups())
a) (‘we’, ‘are’, ‘humans’)
b) (we, are, humans)
c) (‘we’, ‘humans’)
d) ‘we are humans’
View Answer
Answer: a
Explanation: This function returns all the subgroups that have been matched.
6. What is the output of the following?
sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print(matched.group())
a) (‘we’, ‘are’, ‘humans’)
b) (we, are, humans)
c) (‘we’, ‘humans’)
d) ‘we are humans’
View Answer
Answer: d
Explanation: This function returns the entire match.
7. What is the output of the following?
sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print(matched.group(2))
a) ‘are’
b) ‘we’
c) ‘humans’
d) ‘we are humans’
View Answer
Answer: c
Explanation: This function returns the particular subgroup.
8. What is the output of the following?
sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.groupdict())
a) {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
b) (‘horses’, ‘are’, ‘fast’)
c) ‘horses are fast’
d) ‘are’
View Answer
Answer: a
Explanation: This function returns a dictionary that contains all the mathches.
9. What is the output of the following?
sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.groups())
a) {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
b) (‘horses’, ‘are’, ‘fast’)
c) ‘horses are fast’
d) ‘are’
View Answer
Answer: b
Explanation: This function returns all the subgroups that have been matched.
10. What is the output of the following?
sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.group(2))
a) {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
b) (‘horses’, ‘are’, ‘fast’)
c) ‘horses are fast’
d) ‘are’
View Answer
Answer: d
Explanation: This function returns the particular subgroup.
NUMERIC TYPES
1. What is the output of print 0.1 + 0.2 == 0.3?
a) True
b) False
c) Machine dependent
d) Error
View Answer
Answer: b
Explanation: Neither of 0.1, 0.2 and 0.3 can be represented accurately in binary. The round off errors from 0.1 and 0.2 accumulate and hence there is a difference of 5.5511e-17 between (0.1 + 0.2) and 0.3.
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
View Answer
Answer: c
Explanation: l (or L) stands for long.
3. What is the type of inf?
a) Boolean
b) Integer
c) Float
d) Complex
View Answer
Answer: c
Explanation: Infinity is a special case of floating point numbers. It can be obtained by float(‘inf’).
4. What does ~4 evaluate to?
a) -5
b) -4
c) -3
d) +3
View Answer
Answer: a
Explanation: ~x is equivalent to -(x+1).
5. What does ~~~~~~5 evaluate to?
a) +5
b) -11
c) +11
d) -5
View Answer
Answer: a
Explanation: ~x is equivalent to -(x+1).
6. Which of the following is incorrect?
a) x = 0b101
b) x = 0x4f5
c) x = 19023
d) x = 03964
View Answer
Answer: d
Explanation: Numbers starting with a 0 are octal numbers but 9 isn’t allowed in octal numbers.
7. What is the result of cmp(3, 1)?
a) 1
b) 0
c) True
d) False
View Answer
Answer: a
Explanation: cmp(x, y) returns 1 if x > y, 0 if x == y and -1 if x < y.
8. Which of the following is incorrect?
a) float(‘inf’)
b) float(‘nan’)
c) float(’56’+’78’)
d) float(’12+34′)
View Answer
Answer: d
Explanation: ‘+’ cannot be converted to a float.
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
View Answer
Answer: b
Explanation: Python rounds off numbers away from 0 when the number to be rounded off is exactly halfway through. round(0.5) is 1 and round(-0.5) is -1.
10. What does 3 ^ 4 evaluate to?
a) 81
b) 12
c) 0.75
d) 7
View Answer
Answer: d
Explanation: ^ is the Binary XOR operator.


TECH$type=three$author=hide

Name

5G Technology,1,Abbreviations,2,Agent AI,1,Agentic Ai,1,AI in Education,1,AI in Healthcare,1,AI in surgery,1,AI Reasoning,1,Algorithm,1,Algorithms,4,android,2,Artemis Mission,1,Artificial Intelligence,5,Artificial Intelligence AI,2,Artificial Neural Networks,1,ASCI and UNI),1,Augmented Reality,1,Automata,3,Blockchain,1,Blockchain Technology,1,C Language,2,C Programming,1,c#,1,C++,2,C++ Programming,1,CakePhp,1,Carbon Neutrality,1,CCNA,1,Cellular Communication,1,Chatgpt,1,Cloud Computing,4,Compiler Construction,1,Compiler Construction Solved MCQs,1,Compiler Design,1,Computer,18,Computer Applications,1,Computer Architecture,3,Computer Arithmetics,1,Computer Basics,1,Computer Codes (BCD,1,Computer Fundamentals,5,Computer Graphics,4,Computer Networking,2,Computer Networks,4,Computer Organization,1,Computer Science,2,Computer Short Cut Keys,1,Computer Short Keys,1,CPU Sceduling,1,Cryptocurrency,1,CSS,1,CSS PMS,1,Current Trends and Technologies,1,Custom Hardware,1,Cyber Security,6,Cybercrimes,1,DALL-E,1,Data Communication,1,Data Privacy,1,Data structures,3,Database Management System,4,DBMS,4,Deadlock,1,DeepSeek,1,Digital Systems,1,Digital Systems Solved MCQs - Part 2,1,Discrete Mathematics,2,Discrete Structure,1,dot Net,1,EBCDIC,1,Edge Computing,2,English,1,Ethical AI and Bias,1,Ethics,1,Explainable AI (XAI),1,File System,1,Flowcharts,1,General Data Protection Regulation GDPR,1,General Knowledge,1,Generative AI,2,Gig Economy,1,Graphics Designing,1,Helping Materials,1,HTML,1,HTML 5,1,hybrid work model,1,Inference Optimization,1,Information Systems,1,Information Technology,1,Inpage,1,intelligence,1,Internet,1,Internet Basics,1,Internet of Things,1,Internet of things IOT,2,IT,1,JavaScript,1,jQuery,1,Language,11,Languages Processor,1,Languge,1,Li-Fi,1,Linux/Unix,2,Magento,1,Memory Management,1,Microprocessor,1,Microsoft PowerPoint,1,MidJourney,1,mindfulness apps,1,MS Access,1,MS DOS,1,MS Excel,1,MS Word,2,Multimodal AI,1,NASA,1,Number System,1,Object Oriented Programming (OOP),1,Object Oriented Programming(OOP),1,Operating System,9,Operating System Basics,1,oracle,2,Others,1,Pakistan,1,PCS,1,PHP,1,PMS,1,Process Management,2,Programming,3,Programming Languages,1,Python,2,python language,1,Quantitative Aptitude,2,Quantum Computing,2,R Programming,1,Ransomware,1,Robotic Process Automation RPA,1,Robotics,2,Ruby Language,1,search engine optimization,1,Semester III,2,seo,1,Sloved MCQs on Microsoft Power Point - updated,1,Software Engineering,3,Solved MCQs of MS Access - Updated,1,Solved MCQs on Computer Fundamentals,1,SpaceX Starship,1,SQL,1,System Analysis and Design,1,Theory of Computation,1,Trends and Technologies,1,Virtual Reality,1,web,1,web Fundamental,1,Web Technologies,2,Web3,1,WEB3 Technology,1,x8086,1,zoology,1,
ltr
item
COMPUTER SCIENCE SOLVED MCQS: Solved MCQs on Python
Solved MCQs on Python
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV7OGttvMjraIQiWnaSCFRIFvOQStvibJ3e5Tgx2yW4zhyphenhyphenkOjz-uKUjhjWCyS5Lc0eILrOcCopJIHV6xWupeMPwcTTY6xf5i41-tagCvg1-fM1IEC0CVQOXPwd_-G5ynhoWrQRq2Cv154/s320/pythonlogo.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjV7OGttvMjraIQiWnaSCFRIFvOQStvibJ3e5Tgx2yW4zhyphenhyphenkOjz-uKUjhjWCyS5Lc0eILrOcCopJIHV6xWupeMPwcTTY6xf5i41-tagCvg1-fM1IEC0CVQOXPwd_-G5ynhoWrQRq2Cv154/s72-c/pythonlogo.jpg
COMPUTER SCIENCE SOLVED MCQS
https://cs-mcqs.blogspot.com/2017/08/solved-mcqs-on-python_6.html
https://cs-mcqs.blogspot.com/
https://cs-mcqs.blogspot.com/
https://cs-mcqs.blogspot.com/2017/08/solved-mcqs-on-python_6.html
true
1616963833964386058
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content