logo
  • Home
  • Rank
  • Tests
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

Python Multiple Choice Questions | MCQs | Quiz

Python Interview Questions and Answers
Practice Python questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Variable Names
•   Basic Operators
•   Core Data Types
•   Numeric Types
•   Precedence Associativity-1
•   Precedence Associativity-2
•   Bitwise - 1
•   Bitwise - 2
•   Boolean
•   Formatting - 1
•   Formatting - 2
•   Advanced Formatting
•   Decorators
•   While & For Loops - 1
•   While & For Loops - 2
•   While & For Loops - 3
•   While & For Loops - 4
•   While & For Loops - 5
•   While & For Loops - 6
•   Strings - 1
•   Strings - 2
•   Strings - 3
•   Strings - 4
•   Strings - 5
•   Strings - 6
•   Strings - 7
•   Strings - 8
•   Strings - 9
•   Strings - 10
•   Strings - 11
•   Strings - 12
•   Strings - 13
•   Lists - 1
•   Lists - 2
•   Lists - 3
•   Lists - 4
•   Lists - 5
•   Lists - 6
•   Lists - 7
•   List Comprehension
•   List Comprehension - 1
•   List Comprehension - 2
•   Matrix List Comprehension
•   Tuples - 1
•   Tuples - 2
•   Tuples - 3
•   Sets - 1
•   Sets - 2
•   Sets - 3
•   Sets - 4
•   Sets - 5
•   Dictionary - 1
•   Dictionary - 2
•   Dictionary - 3
•   Dictionary - 4
•   Built-in Functions - 1
•   Built-in Functions - 2
•   Built-in Functions - 3
•   Function - 1
•   Function - 2
•   Function - 3
•   Function - 4
•   Argument Passing - 1
•   Argument Passing - 2
•   Global vs Local Variables-1
•   Global vs Local Variables-2
•   Recursion
•   Shallow Copy vs Deep Copy
•   Functional Tools
•   Mapping Functions - 1
•   Mapping Functions - 2
•   Mapping Functions - 3
•   Python Modules
•   Math - 1
•   Math - 2
•   Math - 3
•   Datetime Module - 1
•   Datetime Module - 2
•   Random Module - 1
•   Random Module - 2
•   Sys Module
•   Operating System
•   Turtle Module - 1
•   Turtle Module - 2
•   Turtle Module - 3
•   Pickle Module
•   Regular Expressions
•   Regular Expressions - 1
•   Regular Expressions - 2
•   Regular Expressions - 3
•   Regular Expressions - 4
•   Regular Expressions - 5
•   Files - 1
•   Files - 2
•   Files - 3
•   Files - 4
•   Files - 5
•   Operator Overloading
•   Classes & Objects - 1
•   Classes & Objects - 2
•   Inheritance - 1
•   Inheritance - 2
•   Polymorphism
•   Encapsulation
•   Exception Handling - 1
•   Exception Handling - 2
•   Exception Handling - 3

Python Tests

Python Tests

Best Reference Books

Python Books

« Prev Page
Next Page »

Python Questions and Answers – Argument Parsing 2

Posted on August 6, 2017 by Manish

This set of Tricky Python Questions & Answers focuses on “Argument Parsing”.

1. What is the output of the following code?

advertisement
def foo(k):
    k = [1]
q = [0]
foo(q)
print(q)

a) [0].
b) [1].
c) [1, 0].
d) [0, 1].
View Answer

Answer: a
Explanation: A new list object is created in the function and the reference is lost. This can be checked by comparing the id of k before and after k = [1].

2. How are variable length arguments specified in the function heading?
a) one star followed by a valid identifier
b) one underscore followed by a valid identifier
c) two stars followed by a valid identifier
d) two underscores followed by a valid identifier
View Answer

Answer: a
Explanation: Refer documentation.

3. Which module in the python standard library parses options received from the command line?
a) getopt
b) os
c) getarg
d) main
View Answer

Answer: a
Explanation: getopt parses options received from the command line.

4. What is the type of sys.argv?
a) set
b) list
c) tuple
d) string
View Answer

Answer: b
Explanation: It is a list of elements.
advertisement

5. What is the value stored in sys.argv[0]?
a) null
b) you cannot access it
c) the program’s name
d) the first argument
View Answer

Answer: c
Explanation: Refer documentation.

6. How are default arguments specified in the function heading?
a) identifier followed by an equal to sign and the default value
b) identifier followed by the default value within backticks (“)
c) identifier followed by the default value within square brackets ([])
d) identifier
View Answer

Answer: a
Explanation: Refer documentation.

7. How are required arguments specified in the function heading?
a) identifier followed by an equal to sign and the default value
b) identifier followed by the default value within backticks (“)
c) identifier followed by the default value within square brackets ([])
d) identifier
View Answer

Answer: d
Explanation: Refer documentation.

8. What is the output of the following code?

def foo(x):
    x[0] = ['def']
    x[1] = ['abc']
    return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))

a) True
b) False
c) None
d) Error
View Answer

Answer: a
Explanation: The same object is modified in the function.
advertisement

9. Where are the arguments received from the command line stored?
a) sys.argv
b) os.argv
c) argv
d) none of the mentioned
View Answer

Answer: a
Explanation: Refer documentation.

10. What is the output of the following?

def foo(i, x=[]):
    x.append(x.append(i))
    return x
for i in range(3):
    y = foo(i)
print(y)

a) [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]].
b) [[0], [[0], 1], [[0], [[0], 1], 2]].
c) [0, None, 1, None, 2, None].
d) [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]].
View Answer

Answer: c
Explanation: append() returns None.

Sanfoundry Global Education & Learning Series – Python.

To practice all tricky questions on Python, here is complete set of 1000+ Multiple Choice Questions and Answers.

« Prev Page - Python Questions and Answers – Argument Parsing 1
» Next Page - Python Questions and Answers – Global vs Local Variables – 1

« Python Questions and Answers – Argument Parsing 1
Python Questions and Answers – Global vs Local Variables – 1 »
advertisement

Deep Dive @ Sanfoundry:

  1. Java Programming Examples on Inheritance
  2. C++ Questions and Answers
  3. Object Oriented Programming Questions and Answers
  4. Java Programming Examples on Classes
  5. Python Programming Examples
  6. Python Questions and Answers
  7. Python Questions and Answers – Operator Overloading
  8. Python Questions and Answers – Python Modules
  9. Python Question and Answers – Sys Module
  10. Python Questions and Answers – Tuples – 2
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.