May 2019
Beginner
528 pages
29h 51m
English
In earlier chapters, we used the + operator to concatenate strings and the * operator to repeat strings. You also can perform these operations with augmented assignments. Strings are immutable, so each operation assigns a new string object to the variable:
In [1]: s1 = 'happy'In [2]: s2 = 'birthday'In [3]: s1 += ' ' + s2In [4]: s1Out[4]: 'happy birthday'In [5]: symbol = '>'In [6]: symbol *= 5In [7]: symbolOut[7]: '>>>>>'
(IPython Session) Use the += operator to concatenate your first and last name. Then use the *= operator to create a bar of asterisks with the same number of characters ...
Read now
Unlock full access