我试图在这里调用我的函数,它在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>
函数定义不执行函数体;仅在调用该函数时才执行。
要调用函数,请在函数名称后加上括号:
def my_function():
print("Hello from a function")
my_function()
正如其他人所说,您需要使用方括号,即:
print(get_song_input())