当然,这是非常简单的程序。 你应该等都指串的方法和串索引python中得到明确的想法。 让我解释这个在deatial.
print(reverse_string('hello'))//打印功能是打电话的另一个功能
reverse_string并通过参数"你好"。
def reverse_string(string)://参数"hello"存在的可变
串在reverse_string功能。
**new_strings = []** // created a new empty list
**index = len(string)** // len function returns the length of the argument
passed to the function. len("hello")=5 and assigned
to index. index=5.
虽然索引: //while循环exicute,直至情况得到错误的。在此
例的时候指数=0.在串度从0开始。对于
例。
string[0]=h,string[1]=e、串[2]=l,string[3]=l,string[4]=o.
**index -= 1** //Note the last letter 'o' is in string[4] and the len
function returned 5 so we need to decrement index variable
to 4 so that it will pointing to string[4]=o
new_strings.append(string[指标]) //追加string[4]这是o等等...
返回"。加入(new_strings)