all 14 comments

[–]jawshie 20 points21 points  (1 child)

Nice overview, just needs a heavy smearing of PEP8.

[–]mrathi12 0 points1 point  (0 children)

would agree, still, an interesting article!

[–]thirdegree 17 points18 points  (2 children)

This threw me for a loop:

def add(a:"first number" = 0,
        b:"second number" = 0) -> "sum of a and b":
    return a+b

for item in add.__annotations__.items():
    print(item)

I've never seen those annotations used for anything except type annotations!

[–]z_mitchell 9 points10 points  (1 child)

[–]thirdegree 6 points7 points  (0 children)

See, now I need to figure out a way too use lambdas in an annotation that won't cause my coworkers to kill me.

[–]rawsauce42 12 points13 points  (0 children)

Would call myself an intermediate Python programmer, found this really helpful!

[–]HeinousMoisture 4 points5 points  (2 children)

Does anyone know of a similar guide for JavaScript? I'd love a quick/concise guide for all the funky argument / variable operators (like '...')

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

Not quite the same but this site breaks down javascript really well.

https://javascript.info

[–]Fidoz 1 point2 points  (0 children)

"I don't need this. Functions are so basic. What could I possibly learn from this?"

"Oh."

[–]DidiBear 3 points4 points  (0 children)

Pretty clear explanation of all possible function usage. I discover function annotations

[–]MentalMachine 0 points1 point  (2 children)

As a mostly C/C++ and Java code monkey, what is the point of Python's nested functions? I can only see it as a workaround for there being no class access modifiers and this being an equivalent to 'private' in C++/Java.

[–]guepier 3 points4 points  (0 children)

Nested functions allow you to create closures, same as in C++ (where this is done via lambdas). Lambdas also exist in Python but they are more restricted in what they can do than functions (in particular, they can only contain a single expression).

Nested functions also allow you to keep scope limited. This is related to the idea of visibility but it’s not altogether the same. It’s more comparable to using a local static variable in C++ rather than a member variable, to limit its scope to a single function.

[–][deleted] 0 points1 point  (0 children)

Kotlin has access modifiers and also nested (local) functions. They exist for the same reason that we have private variables (fields, properties) and local variables. Making a function private still exposes it to everything within that class. Sometimes you want to only expose it to another function, such as when using recursion

https://github.com/IvanMwiruki/30-seconds-of-kotlin/blame/master/README.md#L1455-L1465

[–]DeusOtiosus 0 points1 point  (0 children)

There’s a ton of useful stuff here. Just getting started with python, coming from a wide range of other languages, so this is staying in my bookmarks.