Jun-15-2020, 12:20 PM
(This post was last modified: Jun-15-2020, 12:20 PM by glennford49.)
(Jun-15-2020, 12:00 PM)buran Wrote:result_names = 'elena' dict={"glenn":1,"elena":2} def person(names): pins =dict.get(names) return pins pins = person(result_names) print(pins)you need to assign the value returned from the function to a name (unless you use it directly and not plan to use it again)
by the way, don't usedict
as variable name - it's a build in function.
Also, you use it inside the function (as global name). It's better either have it inside the function or pass it as argument like you do withnames
(in which case there is the question do you need the function at all)
name = 'elena' def get_pin(name): """ Given a name, return pin """ users = {"glenn":1, "elena":2} pin = users.get(name) return pin # you can replace this line and the previous with return users.get(name) pin = get_pin(name) print(pin)
thanks... it works like a charm +1 for you