In fact the operator +
in this context makes the concatenation of texts in a simple way, which means that it will generate another object that will contain the contents of the two objects used with the operator, and that object will be used wherever necessary, for example can be an argument to pass to a function as it was used in the first code. The concatenation by chance is being composed with the function print()
.
The operator ,
has nothing to do with it, it serves to separate elements in a list in some contexts, and the exact shape varies according to the context.
The function print()
accepts several arguments. From 0 to virtually unlimited can be used because it is like passing a array. How do you separate each argument to be passed to a function? Simple, that’s a list of arguments, separates with the comma.
So in the second code is calling the function by passing two arguments to the function print()
. By chance who wrote it determined that this function would print the arguments that come after the first with a separate blank space. In that context it happens, but it is what the print()
does, does not serve for other situations in the language.
It may seem that the result is almost the same, but what is happening is totally different. No new object is created for this, so it is more efficient.
It’s actually more complicated than you think. I’m sorry to inform you, but you seem to be learning in a way that doesn’t give you a sense of how things really work in code, so you’re gonna have a hard time forever if you don’t change the way you learn.
When you learn the causes and consequences you can build more advanced code in each step you take and program that is it, understand each concept and go combining them correctly to produce the best result. When you learn only the results you can only do what you’ve seen someone do before, and that’s not programming.
Let me give you an example that sounds silly. Why did you give space before opening parentheses in one function and not in the other? Both work. But understanding why it gives space or why it’s better without space makes a difference to actually understand what the code is, why it’s doing that. It works to do randomly as it is in the code, but without thinking about what you’re writing, you’ll see that there’s a reason not to use space there and you’ll take the first step to be more aware of everything you write and understand every detail of the code, even the ones that don’t seem important, but that has a meaning.
That’s what differentiates who’s new for a while and who’s new for a lifetime. But of course everyone can choose the path they think best, I gave the tip because it seemed like they want to learn the right one.
That’s exactly how I feel. I’m studying watching the Lura videos and reading a book called "Intensive Python Course", the videos are based on taking a project, and teaching you how to do it, but there are no specific videos about each function, many things are passed very quickly, the book presents many things, but without much deepening , in the end I will make 3 projects, the most interesting is a game. Do you know of any course or book that I can delve into? I have a disability in English ( study every day, will soon be solved), in English is not a possibility
– MrLexotan
That’s what courses do, they create an illusion that you’re learning because you see the result. These courses are in the business of creating happiness and not preparing people to be professionals. That’s why they sell so much. And I’m not talking about a specific one, I’m talking about a general one, I can’t individually evaluate any of them. But it’s a bit of a problem for people as well. They believe they can learn simply and quickly, the courses deliver what they want. You have to pick up a lot of content, some boring, you have to look at things that seem irrelevant to a layman, but they’re not.
– Maniero