Outputting Python Programs | Set 22 (Hinges)

Loops | Python Methods and Functions | String Variables

Condition:

mylist = [ `geeks` , `forgeeks` ]

for i in mylist:

  i.upper ()

print ( mylist)

  1. [& # 39; GEEKS & # 39 ;, & # 39; FORGEEKS & # 39;].
  2. [& # 39; geeks & # 39 ;, & # 39; forges & # 39;].
  3. [No, no].
  4. unexpected th

Output:

 2. [`geeks`, `forgeeks`] 

Explanation: function does not change the line in place, it returns a new line that is not saved anywhere.

2. What is the result of the following?

mylist = [ ` geeks` , `forgeeks` ]

for i in mylist:

mylist.append (i.upper ())

print (mylist)

  1. [& # 39; GEEKS & # 39 ;, & # 39; FORGEEKS & # 39;].
  2. ["geeks", "forges", Geeks "," Fugiki "].
  3. [No, no].
  4. None of them

Exit:

 4. None of these 

Explanation: The loop does not break as new items are added to the list at each iteration.

3. What is the result of the following?

i = 1

while True :

if i % 0O7 = = 0 :

break

print (i)

i + = 1

  1. 1 2 3 4 5 6.
  2. 1 2 3 4 5 6 7.
  3. error.
  4. None of them

Output:

 1. 1 2 3 4 5 6 

Explanation: the loop will stop when equals 7.

4. What is the result of the following?

True = False

while True :

  print ( True )

  break

  1. False.
  2. True.
  3. Error.
  4. None of them

Exit :

 3. Error 

Explanation: SyntaxError, is a keyword and cannot be changed.

5. What is the result of the following?

i = 1

while True :

if i % 3 = = 0 :

break

print (i)

i + = 1

  1. 1 2 3.
  2. 1 2.
  3. Syntax error.
  4. None of them

Output:

 3. Syntax Error 

Explanation: SyntaxError, between + and = should not be a space ,





Get Solution for free from DataCamp guru