본문 바로가기
<개인공부> - IT/[Python]

Reverse String 함수 만들기

by Aggies '19 2018. 8. 20.
반응형
# Make a function reverse_string that, given a string,
# returns that string in reverse
#
# >>>> reverse_string("arg")
# gra
# >>>> reverse_string("Hi!")
# !iH

def reverse_string(string):
# Add code here that returns the answer
revString = ""

# Reversed keyword : Making decremented for loop
for i in reversed(range(len(string))):
revString += string[i]
return revString
# Add print statements here to test what your code does:
print (reverse_string("arg"))
print (reverse_string("Hi!"))

Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux

gra

!iH

Reference site : https://hourofpython.trinket.io/python-challenges#/string-challenges/reverse-slicing-challenge


반응형