Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


in A=request.args.get('B',C), what is B doing?

hi, i know in this line of code. we are assigning A to be C (so if C=1.5, a new item A will be 1.5). but what is B for? I was also confused in the X=kwargs.get('Y',Z) example, i didn't know whats 'Y' for? more explicitly, if we have:

class A:
  def _ _init_ _(self, **kwargs):
     self.age = kwargs.get('age',26)

what is that 'age' for?our instance Q in class A will only have Q.age=26, so to me we can just make it anything? like self.age = kwargs.get('bud_lite_beer',26)?

1 Answer

Wairton RebouƧas
Wairton RebouƧas
8,225 Points

Hi, I think you're misinterpreting the meaning of .get method. the expression A = args.get('B',C) means:

"look at a dictionary called args and search for the value of key 'B', if this key does not exists use C as value instead."

example: sample = {'key1': 3} a = sample.get('key1', 4), a is 3 but in a = sample.get('key2', 4), a is 4