Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
small beginner problem
#1
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]
Reply
#2
Line 7 is never executed, because returning from a function immediately returns to the caller.
Reply
#3
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner having Syntax Error problem RyanHo 3 2,325 Sep-10-2020, 08:33 AM
Last Post: cnull
  Beginner, my recursion returns None, and related problem zpacemanzpiff 2 1,741 Jul-02-2020, 04:25 AM
Last Post: zpacemanzpiff
  Beginner problem, replace function with for loop Motley_Cow 9 4,531 Sep-13-2019, 06:24 AM
Last Post: Motley_Cow
  Beginner problem in python script Cedmo 3 2,722 Jul-04-2019, 08:22 PM
Last Post: Cedmo
  Beginner Problem python 2.7 Jonathan_levy 2 2,635 Jul-04-2018, 08:46 PM
Last Post: ichabod801
  Beginner Problem python 2.7 Jonathan_levy 2 2,678 Jul-03-2018, 11:58 AM
Last Post: gruntfutuk
  problem about 'if' and 'for' from a python beginner yzjnpu 3 2,999 Jun-26-2018, 03:47 PM
Last Post: buran
  Beginner. Calculator problem ¯\_(ツ)_/¯ stykus1992 0 2,291 Feb-15-2018, 11:01 AM
Last Post: stykus1992

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020