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'
Este exercício faz parte do curso
Python for R Users
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Add 'the quick' to 'brown fox'
print('the quick' ____)