1. Learn
  2. /
  3. Courses
  4. /
  5. Python for R Users

Connected

Exercise

Arithmetic with strings

Similar to R, you can use Python as a calculator to perform arithmetic on numerical values. For example, adding two values, 42 + 3.14 or multiplying values, 7 * 9. However, unlike R, Python allows you to use certain mathematical operators on non-numeric values. When you use + on strings, it will concatenate them together:

print('hello' + 'world')

'helloworld'

When you multiply a string by an integer, n, the string will be repeated n times:

print('hello' * 3)

'hellohellohello'

Finally, if you place two strings next to each other, they will also be concatenated:

print('hello' 'world')

'helloworld'

Instructions 1/3

undefined XP
    1
    2
    3

Add the string 'the quick' to the string 'brown fox'.