Python Forum

Full Version: small beginner problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey Everyone,

I just started with python so i have a little beginner problem here.
I found out that my funcion wont append the dictionary to the list. but i dont understand why.
I guess for everyone who knows python a bit better than me, the problem is simple and obvious.
So if anyone could help me, i would be really happy.

alben = []

def make_album (artist_name, album_title):
    """returns album data"""
    album = {'artist name: ': artist_name.title() , 'album title: ': album_title.title()}
    return album
    alben.append(album)

a_album = make_album ( 'tool','salival')
b_album = make_album ('selektivton','in the woods')
c_album = make_album ('john frusciante','the empyrean')


for i in alben:
    print(i)
Output:
[Finished in 0.1s]
Line 7 is never executed, because returning from a function immediately returns to the caller.
(Nov-17-2020, 03:20 PM)ndc85430 Wrote: [ -> ]Line 7 is never executed, because returning from a function immediately returns to the caller.

Tanks a lot for this quick response. ok i understand. and yes, switching the lines 6 and 7 worked.