How to reverse a string if the string length is a multiple of 2 in Python

1 Answer

0 votes
def reverse_string(str):
    if len(str) % 2 == 0:
       return ''.join(reversed(str))
    return str

print(reverse_string('python'))
print(reverse_string('c++'))


  
  
'''
run:
  
nohtyp
c++
 
'''

 



answered Sep 1, 2021 by avibootz
...