small medium large xlarge

 

PracProg2strings

Working with Text

1.

   a.'ComputerScience'
   b."Darwin's"
   c.'H2OH2OH2O'
   d.''

2.

   a. "They'll hibernate during the winter."
   b. '"Absolutely not," he said."
   c. '''"He said, 'Absolutely not,'" recalled Mel.'''
   d. 'hydrogen sulfide'
   e. 'left\\right'

3.

   'A\nB\nC'

4.

>>> len('')
0

5.

6. Doe, John

8.

def repeat(s, n):
    """ (str, int) -> str

    Return s repeated n times; if n is negative, return the empty string.

    >>> repeat('yes', 4)
    'yesyesyesyes'
    >>> repeat('no', 0)
    ''
    >>> repeat('no', -2)
    ''
    >>> repeat('yesnomaybe', 3)
    'yesnomaybeyesnomaybeyesnomaybe'
    """ 
    return s * n
Page History
  • V11: Paul Gries [about 3 years ago]
  • V10: Jennifer Campbell [about 3 years ago]
  • V9: Jennifer Campbell [about 3 years ago]
  • V8: Jennifer Campbell [about 3 years ago]
  • V7: Jennifer Campbell [about 3 years ago]
  • V3: Jennifer Campbell [about 3 years ago]
  • V6: System [about 3 years ago]
  • V5: System [about 3 years ago]
  • V4: System [about 3 years ago]
  • V2: Jason Montojo [about 3 years ago]