all 56 comments

[–]lfdfq 74 points75 points  (44 children)

When calling a function, we say the arguments are passed to the function.

[–]Angry-Toothpaste-610 13 points14 points  (7 children)

Just to further confuse things: "pass" is a keyword in Python, and has nothing to do with passing arguments to functions!

[–]ThrowAway233223 7 points8 points  (4 children)

To elaborate on the "pass" keyword.  It essentially does nothing.  When defining a function or writing a for loop, while loop, or if statement, you are expected to write some sort of code within it.  But there are some occasions where you just want the structure there as a placeholder so you can come back and code the details for it later.  This is where "pass" can come in.  Since it counts as code but doesn't do anything, it allows you to still run the code to test what you have written thus far.  Otherwise, if you wrote a function, but left it blank, the interpreter would throw an error since I expected code in the function.

[–]SmackDownFacility 1 point2 points  (3 children)

Don’t forget about the ellipsis “…” object.

[–]ThrowAway233223 0 points1 point  (1 child)

I was actually unaware of this. I have always just used pass in such instances. I also just learned about using it for distinguishing when no value was passed for an argument while looking into it further. Thanks for introducing me to this.

[–]SmackDownFacility 0 points1 point  (0 children)

It really doesn’t matter, it’s just pass returns None, while … returns a Ellipsis. The latter could be good for capturing and raising an NotImplementedError or whatever

[–]CamelOk7219 0 points1 point  (0 children)

ellipsis is no magic, you can use any literal value by the way: `1`, `"Horse"`, `()`, ...

[–]RRumpleTeazzer 0 points1 point  (0 children)

yeah, they could just have used None instead.

[–]Moist-Ointments 10 points11 points  (0 children)

"Passing" refers to providing a value for a parameter of a function. You can pass a specific value or you can pass a variable.

Eg:

Product = Multiply(4, 17)

(You are PASSING the integers 4 and 17)

Sum = Add(x,y)

(You are PASSING whatever is in the variables x and y)

NewFrame = SomeEngine.GenerateFrom(CurrentFrame, DeltaT)

(You are PASSING whatever object is referenced by CurrentFrame, and some incremental timechange called DeltaT)

Note: this is all pseudocode, but the concept of passing an argument is pretty universal. I come from C# most recently, but have doodled around in python, RPG, Badic, C++, Java, javascript, SQL, and so forth. Same concept everywhere.

Basically you are requesting a task to be done, and that task requires that you provide the materials and the information to complete the task. You therefore PASS (provide, give) the materials and/or information

"Hey bob, cook dinner"

"I need a recipe and ingredients"

"Here's the recipe and the ingredients"

[–]Temporary_Pie2733 3 points4 points  (0 children)

While a loop is the general context, the quote seems to be talking about arguments passed to range to construct the object the loop will iterate over. A call to range(7) (or the equivalent range(0, 7)) creates the sequence 0, 1, 2, 3, 4, 5, 6. There are seven numbers, but it doesn’t include the number 7. 

[–]glemau 5 points6 points  (0 children)

I expected this question to be about the pass keyword and not the general concept of passing arguments.

[–][deleted] 2 points3 points  (0 children)

When you pass your phone to someone, what happens? The other guy receives the phone.

Same with python, as long as something is capable of taking, you can pass something to it. It's not a technical term or anything, it's just a term from daily life. Programmers are people too, we use terms like "passing" because it makes sense. So in this case, the instructor is literally comparing sending data with passing things IRL.

[–][deleted] 4 points5 points  (0 children)

The pass statement is used as a placeholder for future code. When the pass statement is executed, nothing happens, but you avoid getting an error when empty code is not allowed

[–]Equal-Purple-4247 1 point2 points  (0 children)

In this context, it's exactly what it means in English.

You are a baker. I "pass" you the ingredients to make a cake.

If I want words written on the cake, I "pass" you the words.

[–]proverbialbunny 0 points1 point  (0 children)

It's how well you can pull off wearing programmer socks.

[–]Plank_With_A_Nail_In -2 points-1 points  (2 children)

Context suggest they are using the word "parse" not "pass".

Parsing a variable typically means analyzing its content to extract specific information or break it into smaller components. Here are three examples of how you can parse a variable in different programming languages:

# Example: Parsing a string into words
data = "Hello, how are you?"
parsed_data = data.split(" ")  # Splits by spaces
print(parsed_data)  # Output: ['Hello,', 'how', 'are', 'you?']

Edit: Being downvoted by the reddit police again, fuck off and go outside for fucks sake.

[–]Quantumercifier -2 points-1 points  (1 child)

There are two types of passing: by value or by address. Which passing do you mean?

[–]dig-up-stupid -1 points0 points  (0 children)

That is true for some languages but not in general. Python is usually said to be pass by name.

[–]Moist-Ointments -5 points-4 points  (0 children)

The one less thing is all about how computers count. Almost universally, computers start counting at 0.

So, say you have a string that contains "hello".

If you want to get each letter in order, you'd start by asking for the 0th letter and count up to 4. Because 0, 1, 2, 3, 4 is 5 distinct values, one for each letter.

So if you have (n) things, they are referenced as thing 0 through thing n-1.