how to print a word backwards in python code example
Example 1: how to reverse word order in python
string = "I am a python programmer"
words = string.split()
words = list(reversed(words))
print(" ".join(words))
Example 2: reverse each word in a string python
def reverse_word_sentence (sentence):
return ' '.join(word[::-1] for word in sentence.split(" "))
Example 3: reverse string method python
def reverse(s):
str = ""
for i in s:
str = i + str
return str
'hello world'[::-1]
def reverse(string):
string = "".join(reversed(string))
return string
Example 4: reverse a string in python
example_number = 12143
example_string = "Hello there"
def reverse(thing):
thing = str(thing)
list_of_chars = [char for char in thing]
reversed_list_of_chars = []
x = -1
for char in list_of_chars:
reversed_list_of_chars.append(list_of_chars[x])
x += -1
reversed_thing = ''.join(reversed_list_of_chars)
return reversed_thing
print(reversed_thing)
reverse(example_number)
reverse(example_string)