反转 python 中不是列表的函数的输出

Reversing the output of a function in python that is not a list

这段代码的输出我会得到一个数字:

base = int(raw_input("Pick your base:  "))
base = str(base)
question = "Pick your number! (the base is "+base+" ):  "
number = int(raw_input(question))
def func(number):
    if number != 0: 
        sec = number/int(base)
        third = number - (sec * int(base)) 
        print third,
        func(sec) 
func(number)

我想获取输出(例如 2435)并将其反转(到 5342)。我已经通过将 func(number) 分配给变量然后打印 variable[::-1] 来尝试 a[::-1] 但这似乎不起作用:

x = func(number)   
print x[::-1]

这给了我:

TypeError: 'NoneType' object has no attribute 'getitem'

您的方法 func 缺少 return 语句(因此 returns None)。如果没有返回值,则无法对其应用索引运算符。