Python Programming Language MCQ with Answers Set 4

 

1. The ------ function is used to get data type of variable





ANSWER= (D)type()
Explain:-The type function in Python is used to get data type of particular variable

 

2. The ------ function is used to join strings into one string





ANSWER= (C)join()
Explain:-In Python join() is used to join strings into one string

 

3.What is missing in following statement 

if a==10 

     print(a)





ANSWER= (C):(colon)
Explain:- in the if statement syntax : colon is also part of syntax and it is missing

 

4. What is missing in following statement 

while a<10:

 print(a)





ANSWER= (C)both of above
Explain:- in the while statement syntax, indentation is the space given before starting new code line in the for block

 

5. The ------ are not used to declare variables in Python





ANSWER= (C)both of above
Explain:- The keywords or reserve words are not used to declare variables in Python

 

6. The range() method in for loop is used to pass ---- , ----- , ------- parameters





ANSWER= (D)All of above
Explain:- In the range() function in for loop there parameters are passed these are start is used to start you loop from initial value or starting value, the stop is used to end of your loop on that value and step parameter is used to increment or decrement the loop value

 

7. What will be the output of below code 

for i in range(1,5,2): 

      print(i)





ANSWER= (A)1 3
Explain:- In the for loop range() function the three parameters are 1,5,2. The initial value is 1. Loop will start from 1. The 5 is passed that your loop will be end on 5. So in the output 5 will not be included. Thir value is step value and it is 2 i.e. sequence will be display by the difference of 2. So output will be 1 and 3.

 

8. What will be the output of below code 

for i in range(6): 

       print(i)





ANSWER= (C)0 1 2 3 4 5
Explain:- In the range function 6 value is passed. Compiler will take this value as etop value or end value. So loop will end on 6 . Start value is not given so lopp will start by default at 0 and step value is also not given so by default loop will be incremented by 1. So final answer will be 0 1 2 3 4 5

 

9. What will be the output of below code i=1 ; while i<5:; print(i)<5: i="" p="" print="">





ANSWER= (B) 1 2 3 4
Explain:- The initial value of while loop is initalized as 1 so loop will start from 1. The test condition is i<5 1="" 2="" 3="" 4="" 5="" and="" be="" by="" continue="" each="" final="" get="" i="i+1." in="" increase="" is="" it="" iteration="" loop="" means="" number="" once="" output="" so="" span="" stop.="" that="" the="" till="" value="" will="">

 

10. What will be the output of below code for i in range(1,10,3): ; print(i)





ANSWER= (D) 1 4 7
Explain:- The start value is 1 loop will start with 1. The end or stop value is 10 so loop iteration will end on 10. So 10 will not be included. Step value is 3 i.e. loop will be incremented by 3. So final answer will be 1 4 7

टिप्पणी पोस्ट करा

0 टिप्पण्या