按函数更改结果-python3

按函数更改结果-python3,python,python-3.x,function,Python,Python 3.x,Function,我需要用4种不同的文献生成随机数, 所以我写了这个程序: import random def rand(): i=0 n="" while i<4: a = str(random.randint(0,9)) if a not in n: n +=a i+=1 return n print (rand) 随机导入 def rand(): i=0 n=“” 当i时,您打印对函数本身

我需要用4种不同的文献生成随机数, 所以我写了这个程序:

import random
def rand():
    i=0
    n=""
    while i<4:
        a = str(random.randint(0,9))
        if a not in n:
            n +=a
            i+=1
    return n
print (rand)
随机导入
def rand():
i=0
n=“”

当i时,您打印对函数本身的引用,而不是调用它。要调用它,需要在它后面加括号(
()
):


您正在打印对函数本身的引用,而不是调用它。要调用它,需要在它后面加括号(
()
):


不是回答问题,而是另一种方法。整个函数体可能如下所示:
return'。join(random.sample('0123456789',4))
不回答问题,而是另一种方法。整个函数体可能如下所示:
return'。join(random.sample('0123456789',4))
<function rand at 0x000001E057349D08>
print (rand())
# Here ----^