Concatenazione di stringhe in Python
Per la concatenazione di stringhe
si utilizza l'operatore +:
pythontest = 'abc' + 'def' # somma di due stringhe
print(test) # stamperà 'abcdef'
Le stringhe possono anche essere memorizzate in variabili:
pythontest1 = 'abc'
test2 = 'def'
test3 = test1 + test2 # somma di due stringhe
print(test3) # stamperà 'abcdef'
È anche possibile sommare variabili e stringhe:
pythontest1 = 'abc'
test2 = 'def'
test3 = test1 + '!!!' + test2
print(test3)
Задание 1
Date due stringhe:
pythontxt1 = 'abc'
txt2 = 'def'
Unisci queste stringhe in una nuova e visualizzala a schermo.
Задание 2
Date le seguenti stringhe:
pythontxt1 = '12'
txt2 = '+'
txt3 = '5'
txt4 = '17'
Unisci queste stringhe in una nuova e visualizzala a schermo.
Задание 3
Modifica la soluzione del problema precedente in modo
che dopo l'unione tra la terza e la quarta
stringa ci sia l'operatore =.