Python 如果我调用我的函数,我应该如何解决这个问题,它 returns 函数对象
Python how should I fix this if I call my function, it returns function object
我试图在这里调用我的函数,它 returns 在 0x7ff9869ee050 函数 get_song_input
我的代码有什么问题?我把它放在 python 可视化工具中,结果很好。
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>
正如其他人所说,您需要括号,即:
print(get_song_input())
函数定义不执行函数体;只有在函数被调用时才会执行。
要调用函数,请使用函数名称后跟括号:
def my_function():
print("Hello from a function")
my_function()
我试图在这里调用我的函数,它 returns 在 0x7ff9869ee050 函数 get_song_input 我的代码有什么问题?我把它放在 python 可视化工具中,结果很好。
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>
正如其他人所说,您需要括号,即:
print(get_song_input())
函数定义不执行函数体;只有在函数被调用时才会执行。
要调用函数,请使用函数名称后跟括号:
def my_function():
print("Hello from a function")
my_function()