Python Forum
small beginner problem - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: small beginner problem (/thread-30997.html)



small beginner problem - FelixReiter - Nov-17-2020

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]



RE: small beginner problem - ndc85430 - Nov-17-2020

Line 7 is never executed, because returning from a function immediately returns to the caller.


RE: small beginner problem - FelixReiter - Nov-17-2020

(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.