Python,如果我调用函数,应该如何解决,它返回 [closed]

问题描述 投票:-1回答:2

我试图在这里调用我的函数,它在0x7ff9869ee050返回函数get_song_input我的代码有什么问题?我把它放在python visualizer中,效果很好。

Album = namedtuple('Album', 'id artist title year songs')  
Song = namedtuple('Song', 'track title length play_count')  


def get_song_input():
    """Prompt user input."""
    songtrack = input('Enter the song\'s track:\n')
    songtitle = input('Enter the song\'s title:\n')
    songlength = input('Enter the song\'s length:\n')
    songplaycount = input('Enter the song\'s play_count:\n')
    song_info = Song(songtrack, songtitle, songlength, songplaycount)
    return song_info

print(get_song_input)

output:
<function get_song_input at 0x7ff9869ee050>
python namedtuple
2个回答
-1
投票

函数定义不执行函数体;仅在调用该函数时才执行。

要调用函数,请在函数名称后加上括号:

def my_function():
  print("Hello from a function")

my_function()

-1
投票

正如其他人所说,您需要使用方括号,即:

print(get_song_input())
© www.soinside.com 2019 - 2024. All rights reserved.