Python Quizzes

Results

-
Share to Your Friend
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Share to Your Friend
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

#1 If s is a set having elements s={1,2,3,4,5,6}, what would be the output of the above program ?

Explanation-

for loop iterates over set s, and it first stores values  in item variable


if checks whether 1 % 2  which is equal to 1

And Python treats non-zero numbers as True  then it prints  value of item which is 1


if checks whether 2 % 2  which is equal to 0

And Python treats zero as False  and  control does not enter in if block


if checks whether 3 % 2  which is equal to 1

And Python treats non-zero numbers as True  then it prints   value of item which is 3


if checks whether 4% 2  which is equal to 0

And Python treats zero as False  and does not enter in if block


if checks whether 5% 2  which is equal to 1

And Python treats non-zero numbers as True  then it prints  value of item which is 5


if checks whether 2 % 2  which is equal to 0

And Python treats zero as False  and does not enter in if block


Answer is

1 3 5

 

 

 

 

 

#2 If d is a dictionary having elements d={‘India’:’New Delhi’, ‘Germany’:’Berlin’, ‘France’:’Paris’, ‘Spain’:’Madrid’}, how will value ‘Berlin’ be accessed.

Click on the  below link to see the explanation

Dictionary in Python

#3 A tuple in Python is

Click on the below link to see the explanation

Tuples in Python

 

 

#4 If t is a tuple having elements t=(1,2,3,4,5,6), how will element 5 be printed?

Click on the below link to see the explanation

Tuples in Python

#5 If a nested list is a=[3,5,8,4,15,34,[5,8,[-4,-8],9,3], 8,9,[6,9],12,7], then how which index you will use to access element -8.

You Can Finish If You Want

Share to Your Friend
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Be the first to comment on "Python Quizzes"

Leave a comment

Your email address will not be published.


*