FAQ: Learn Python: Function Arguments - Default Return

This community-built FAQ covers the “Default Return” exercise from the lesson “Learn Python: Function Arguments”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Python 3

FAQs on the exercise Default Return

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

2 posts were split to a new topic: This is my code

Hey guys!
This might be a question related to another topic, but it came to me at this exercise.
What does that dot actually do, it changes everything in their return:

list_sort_return = sorted(sort_this_list)

and

list_sort_return = sort_this_list.sort()

I understand what each code line does, and been using it for a little time already, but tell me please what does that dot do?

why isn’t it, for example:

list_sort_return = sort_this_list.sorted()

or:

list_sort_return = sort(sort_this_list)

Thx, in advance :slight_smile:

This might be better in the general Get-help Python category but I don’t know that it’s possible to move it.
https://discuss.codecademy.com/c/get-help/python/1802

If you’ve not yet done the method on classes in Python then this description might not be too clear. You can read up about OOP and Python classes in particular or you can hold out until you reach that lesson. I wouldn’t stress about it too much until you’ve covered those topics.

The dot indicates an attribute of the object. In this case the object is a list and lists have a method called sort that adjust the of the list in place according to the key argument you provide it.

Sorted is a funciton that takes any iterable as an argument and sorts it according to the given key. If you already have a list and just want to sort it in place the .sort() method is probably quicker and clearer.

This function makes a copy of the list given in the argument, then returns ti sorted in ascending order. We can reverse the sort with,

new_list = sorted(my_list, reverse=True)

has no return value. It does not create a copy, but sorts in place. We can reverse sort the same as above.

Not a method.

Not a function.

All right, thank you very much, clearer now :slight_smile:

1 Like

Absolutely! I learned, that I shouldn’t worry about these, yet, I will deeply understand them later. My learning technique is to get into many things simultaneously, and try to make basic connections fast, which I can improve in time. I studied physics, and I already have a vague idea about coding, so deeper explanations won’t frighten me :smiley:
Thanks very much! Will definitely look into those lessons you mentioned!


@mtf
dear Roy
I wonder why this code returns two"None", but not the sorted list ? What specific knowledge do I miss?
Thank you very much in advance.

This first None comes from the return value of print(), the second from the return value of object.sort().