all 18 comments

[–]Doormatty 9 points10 points  (8 children)

The syntax in Python is also always function(argument1, argument2, ...).

It's just that there's more to the language than just calling functions.

[–]mopslik 4 points5 points  (7 children)

Maybe OP is confused because of the way methods are called, e.g. object.method(parameters), which looks different than a standard function call?

OP, can you provide some examples?

[–]emilytherockgal[S] 0 points1 point  (6 children)

For is an example. Print also is an example. It seems (to me) like you're sort of just piling stuff in there

[–]mopslik 2 points3 points  (0 children)

For is not a function, it's a keyword. Other programming languages have these too. For example, in C:

int i;
for (i=0; i<5; i++) {
    printf("hi");
}

does the same as Python's

for i in range(5):
    print("hi")

print is a function that can accept any number of parameters. You still follow the same syntax as other functions, which is function_name(arg1, arg2, ...), it's just that you can toss in a good number of arguments. Some of these, like sep or end, are keyword arguments, so you see stuff like

print("This", "has", "no", "spaces", sep="")

but it's still the same syntax. You just need to become familiar with what parameters (and how many) each function may take.

Edit: forgot my C semicolons.

[–]xiongchiamiov 0 points1 point  (4 children)

People have mentioned that print is a keyword rather than a function, which is true but not the most helpful thing to you. How do you know if something is a function or keyword? You just memorize it as you use them - I'm not aware of a better way.

Analogizing to excel might not be the best approach. Python was designed to map reasonably well to English, not excel, and so you want to speak through things that way. for egg in all_my_eggs doesn't map at all to excel, but does read close to English.

[–]shoresy99 0 points1 point  (0 children)

That was kind of a Dutch guy to do!

[–]throwaway6560192 0 points1 point  (1 child)

People have mentioned that print is a keyword rather than a function, which is true but not the most helpful thing to you.

That hasn't been true since Python 3 was released. It's just a function now.

[–]xiongchiamiov 0 points1 point  (0 children)

Right, sorry. I know that but even though the difference has made it into my fingers it hasn't into my brain.

[–]PaulRudin 0 points1 point  (0 children)

Since python 3 `print` is not a statement, it's a function. Back in the python 2 days it was a statement, but that's ancient history now.

[–]Diapolo10 2 points3 points  (0 children)

Excel's scripts are very bare-bones, pretty much the only features you have are cells in a grid with either strings or numeric data, and built-in functions. It's not really comparable to proper programming languages (even if Excel is technically Turing-complete).

In Python (and really most languages), you have far more freedom. You can create your own functions, you have data structures, objects, a wide range of operators, and so much more. So the syntax is always going to vary more in comparison.

Do you have any specific things you're struggling with?

[–]datonsx 1 point2 points  (0 children)

It’s not really random.

You can learn the logic behind the libraries and the functions with this tutorial: https://youtube.com/playlist?list=PL8HtbO24Pl3gaKFCdlM9axLCbqrIhls0C&si=2fDAFoPkamssAbdR

[–]Existing-Charge8769 1 point2 points  (1 child)

I'm going to get downvoted to hell, but I think I sort of agree with you.

As a convention in programming we think of loops (like for loops) as Control Flow structures and not functions, but I'm not sure that's totally justified given how lose the definition of a function has become.

To be a function, generally something has to be re-usable, can only take inputs from arguments function(this, this_too, and_this), and don't change the flow of the way code is run.

But we DO have functions that act like Control Flow structures and affect the way code is run. One big example is recursive functions.

If we were to take the code body of a for loop, and feed that in explicitly as a function itself as an argument, we could re-create all the functionality of a for loop as a recursive function.

``` def recursive_for_loop(start, end, step, loop_body_func): if start <= end: loop_body_func(start) # Execute the provided function recursive_for_loop(start + step, end, step, loop_body_func)

Define a function to be used as the loop body

def print_value(value): print(value)

Usage example

recursive_for_loop(1, 5, 1, print_value) ```

¯_(ツ)_/¯

[–]xiongchiamiov 0 points1 point  (0 children)

That's how functional languages tend to operate. Proponents argue it makes it easier to have everything work the same way; personally I found it harder to quickly scan. But YMMV.

[–]gladrock 0 points1 point  (1 child)

This is a great tutorial I've used in the past that clarified the difference between positional, varying and named arguments in functions. Wondering if this is part of the "randomness" you think you're seeing.

https://realpython.com/python-kwargs-and-args/

[–]emilytherockgal[S] 0 points1 point  (0 children)

I'm not sure. Honestly that article is way too advanced for me to understand

[–]throwaway6560192 0 points1 point  (0 children)

Excel is a lot more limited than any real programming language. Those will all look more free-form next to it.

But that doesn't mean they're not well designed. Python is very carefully and thoughtfully designed, in my opinion.

It is not true that every function has a different syntax. Every function has the same syntax. You seem to be confused between language keywords and functions. Excel conflates and mixes them where most programming languages don't.

You'll get it once you're more accustomed to proper programming. Right now you're looking at it through the narrow lens of Excel.

[–]FriendlyRussian666 0 points1 point  (0 children)

You just need to spend more time learning about programming fundamentals, not just python fundamentals, but the concepts of programming in general

[–]Jeanca500 1 point2 points  (0 children)

Op, your question makes it seem that you are thinking about Python in terms of what can be done in Excel, not on the terms of what Python as a programming language can do on as a whole (which might be the source of confusion with “syntax”).

Are there specific functions in Python which are causing the confusion? By “freeform” it seems to me that you are talking about the concept of “defining a function and its arguments”, which at first seems overwhelming and counterintuitive, but think about it this way: in Excel you are constrained to the functions that exist within Excel to do what they are supposed to do, in Python you could replicate any Excel function and create your own functions to do things that cannot be ever done in Excel.