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 () 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 () below!
Agree with a comment or answer? Like () to up-vote the contribution!
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?
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.
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
Thanks very much! Will definitely look into those lessons you mentioned!
I don’t exactly understand, though. If you’re setting prints_return equal to a print statement that says ‘What does this print function return?’ then why does that sentence not print when you print prints_return?
I’m referring to the Default Returns section of the Python course. i’ll attach it below.
# store the result of this print() statement in the variable prints_return
print("What does this print function return?")
prints_return = print("What does this print function return?")
# print out the value of prints_return
print(prints_return)
# call sort_this_list.sort() and save that in list_sort_return
sort_this_list = [14, 631, 4, 51358, 50000000]
list_sort_return = sort_this_list.sort()
print(list_sort_return)
# print out the value of list_sort_return
I can’t. I know that it has something to do with the print statement that is assigned to prints_return, because, for example, if you had the following code:
prints_return = 'A random sentence I came up with.'
print(prints_return)
Ok. But in functions where we return something, for example a function that returns a product of two numbers, that product also is displayed. What’s it doing if not directing output to the display? Sorry if I’m asking too many questions.
Some interactive python interpreters will output the evaluation of the last expression (repr or str representation) for the sake of debugging but don’t confuse that with something that occurs normally. It definitely won’t happen when running scripts and shouldn’t be relied upon for anything.