No Result
View All Result
Sunday, September 24, 2023
  • Login
Getting Placed
  • Home
  • Jobs
  • Exam
  • Admit Card
  • Result
  • Internship
  • Home
  • Jobs
  • Exam
  • Admit Card
  • Result
  • Internship
No Result
View All Result
Getting Placed
No Result
View All Result

Python MCQs on Tuple: SET 2

Abhishek by Abhishek
March 14, 2021
in Python
0
python

11. What is the data type of (1)?

a) Tuple

b) Integer

c) List

d) Both tuple and integer

Check Answer
Answer: b
A tuple of one element must be created as (1,).

 

12. 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)

Check Answer
Answer: d
Tuple slicing exists and a[1:-1] returns (2,3).

 

13. What will be the output of the following Python code?

>>> a=(1,2,(4,5))

>>> b=(1,2,(3,4))

>>> a<b

a) False

b) True

c) Error, < operator is not valid for tuples

d) Error, < operator is valid for tuples but not if there are sub-tuples

Check Answer
Answer: a
Since the first element in the sub-tuple of a is larger that the first element in the subtuple of b, False is printed.

 

14. What will be the output of the following Python code?

>>> a=(“Check”)*3

>>> a

a) (‘Check’,’Check’,’Check’)

b) * Operator not valid for tuples

c) (‘CheckCheckCheck’)

d) Syntax error

Check Answer
Answer: c
Here (“Check”) is a string not a tuple because there is no comma after the element.

 

15. What will be the output of the following Python code?

>>> a=(1,2,3,4)

>>> del(a[2])

a) Now, a=(1,2,4)

b) Now, a=(1,3,4)

c) Now a=(3,4)

d) Error as tuple is immutable

Check Answer
Answer: d
‘tuple’ object doesn’t support item deletion.

 

16. What will be the output of the following Python code?

>>> a=(2,3,4)

>>> sum(a,3)

a) Too many arguments for sum() method

b) The method sum() doesn’t exist for tuples

c) 12

d) 9

Check Answer
Answer: c
In the above case, 3 is the starting value to which the sum of the tuple is added to.

 

17. Is the following Python code valid?

>>> a=(1,2,3,4)

>>> del a

a) No because tuple is immutable

b) Yes, first element in the tuple is deleted

c) Yes, the entire tuple is deleted

d) No, invalid syntax for del method

Check Answer
Answer: c
The command del a deletes the entire tuple.

 

18. What type of data is: a=[(1,1),(2,4),(3,9)]?

a) Array of tuples

b) List of tuples

c) Tuples of lists

d) Invalid type

Check Answer
Answer: b
The variable a has tuples enclosed in a list making it a list of tuples.

 

19. What will be the output of the following Python code?

>>> a=(0,1,2,3,4)

>>> b=slice(0,2)

>>> a[b]

a) Invalid syntax for slicing

b) [0,2]

c) (0,1)

d) (0,2)

Check Answer
Answer: c
The method illustrated in the above piece of code is that of naming of slices.

 

20. Is the following Python code valid?

>>> a=(1,2,3)

>>> b=(‘A’,’B’,’C’)

>>> c=tuple(zip(a,b))

a) Yes, c will be ((1, ‘A’), (2, ‘B’), (3, ‘C’))

b) Yes, c will be ((1,2,3),(‘A’,’B’,’C’))

c) No because tuples are immutable

d) No because the syntax for zip function isn’t valid

Check Answer
Answer: a
Zip function combines individual elements of two iterables into tuples. Execute in Python shell to verify.

Page  1  2  3

 

Previous Post

Python MCQs on variable and operators: SET 2

Next Post

Python MCQs on Formatting and Advance Formatting: SET 4

Abhishek

Abhishek

Next Post
python

Python MCQs on Formatting and Advance Formatting: SET 4

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Us on Google News
No Result
View All Result

Recent Posts

  • Mustard Oil Price: सस्ता हुआ सरसों का तेल, खरीदने वालों की लगी भीड़
  • Bhojpuri Video: पवन सिंह ने रात के अंधेरे में मोनालिसा के बदन पर फेरा हाथ, मच गया बवाल
  • Gori Nagori ने उछल-उछल कर तोड़ दिया स्टेज, लगाए ताबड़तोड़ ठुमके
  • Haryanvi Dance: भरी जवानी में Gori Nagori के लगाए लटके-झटकें, देख बूढ़ों में आया जोश
  • Gori Nagori ने स्टेज पर उछल उछल कर लगाए जोरदार ठुमके, वायरल हुआ वीडियो

Recent Comments

  • Abhishek on Win 11 Download Links

Archives

  • September 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • August 2022
  • July 2022
  • October 2021
  • July 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • April 2020
  • February 2020

Categories

  • Admit Card
  • Algorithm and Programs
  • Exam
  • Internship
  • Java
  • Jobs
  • latest
  • politics and entertainment
  • Python
  • Result
  • Trademark
  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
  • Privacy Policy
  • DMCA
  • Terms of Use
  • Sitemap

© 2020 Getting Placed

No Result
View All Result
  • Home
  • Jobs
  • Exam
  • Admit Card
  • Result
  • Internship

© 2020 Getting Placed

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In