Omkering van 'n reeks in Python
Om alle elemente van 'n reeks in omgekeerde volgorde om te keer, moet jy 'n stap met 'n negatiewe waarde spesifiseer:
pythontxt = '123456789'
res = txt[::-1]
print(res) # sal '987654321' uitvoer
Задание 1
Gegee 'n string:
pythontxt = '12345'
Keer dit om:
python'54321'
Задание 2
Gegee 'n lys:
pythonlst = ['c', 'b', 'a']
Keer dit om:
python['a', 'b', 'c']
Задание 3
Gegee 'n string:
pythontxt = '123456789'
Kry 'n sny van al sy karakters in ewe posisies in omgekeerde volgorde:
python'8642'