MOBI BOOT CAMP CORP. logoLearning Buddy
  • SIGN IN
  • Introduction
  • Setup
  • 1A: Fundamental Building Blocks
  • 1B: Compound Statements
  • 2: Ordered Collection
  • 3: Unordered Collection
  • 4: More Data types
    • Strings
    • Time and Space Complexity
    • Quiz
    • Colab Exercise
  • 5: Iteration Constructs
  • 6: Other constructs
  • 7. Regex
  • 8. Date and Time
  • Revision
  • Practice Exercise
  • Titanic Workshop

Quiz

a = 'Amazing'
Which expressions will let you print the second character 'm' of this String

a[2] a[1] a[0] a[-6] Index numbers start with 0.

a = 'Amazing'
Which expression will get you the characters from position 0 to index of 'z', including 'z'

a[0:a.find("z") + 1] a[0:a.find("z") - 1] a[0:3] a[:4] a[0:4]
   <question>
       <p>A string is assigned to a variable <pre><code>a = 'Amazing'</code></pre>You wrote an expression to find if the given string has a substring 'zing' <pre><code>a.find('zing')</code></pre> This expression returns the - </p>
       <answer correct>index number 3 where it found the substring zing</answer>
       <answer >index number 4 where it found the substring zing</answer>
       <answer >returns the substring zing</answer>
       <answer>None of the above</answer>
      
    </question>
    
    <question>
       <p>A string is assigned to a variable <pre><code>a = 'amazing'</code></pre>You wrote an expression to capitalize this string <pre><code>a.capitalize()

print(a) This will print -

amazing Amazing None of the above This method returns a new string with the first letter in uppercase. The String 'a' is not changed

    </question>
    
     <question>
       <p>A string is assigned to a variable <pre><code>a = 'amazing'</code></pre>You wrote an expression to find its length <pre><code>print(len(a))</code></pre> This will print - </p>
       <answer correct>7</answer>
       <answer>6</answer>
       <answer>1</answer>
     
      
    </question>
    
     <question>
       <p> What is the result of evaluating this expression <pre><code>'amazing'.count('a', 1)</code></pre></p>
       <answer correct>1</answer>
       <answer>2</answer>
       <answer>0</answer>
        <explanation>Since the start position 1 is given, it counts the number of 'a' from index position 1 </explanation>
              
     </question>
        <question>
         <p> What is the result of evaluating this expression <pre><code>'amazing'.count('a', 0, 2)</code></pre></p>
         <answer correct>1</answer>
         <answer>2</answer>
         <answer>0</answer>
          <explanation>Since the start position 0 and the end position 2 is given, it counts the number of 'a' from index position 1 to index position 2, excluding 2 </explanation>
                
       </question>

        <question>
         <p> Study the code below <pre><code>pi = 3.141592653589793

b = f'{pi:.3f}' print(b) What is the output of the print statement?

3.142 0.142 003.14 Output is restricted to 3 decimal points due to using '.3f'. Digits before the decimal point are untouched.

       </question>
       
       <question>
            <p> Study the code below <pre><code>pi = 3.141592653589793

b = f'{pi:.3f}' print(type(b)) What is the data type of 'b'?

str int bool f-strings, like the format function, convert a numeric value to a String

          </question>
     <question>
            <p> Study the code below <pre><code>t1 = (5, 8)

t2 = (10, 15) d = f'X: {t1[0]}; Y: {t2[1]}' print(d) What is the output?

'X: 5; Y: 15' 'X: 5; Y: 8' 'X: 5; Y: 10' Follow the index positions of the arguments passed in to find the correct output

          </question>
 <question>
         <p> What is output of the given expression?<pre><code>a = 3.14159

f'{a:.0f}'

'3' '3.14159' '3.0' The f-string formats the float to a string with zero decimal places.

 </question>
 
 <question>
              <p> What is output of the given expression? <pre><code>val1 = 'B'

val2 = 10 f'{val2}{val1}'

'10B' 'B10' Error

      </question>

##Exercise

Privacy Policy | Terms & Conditions