Learning a lot about Python from Holly Glaceon :monorail_boop:

@vaporeon_ here's a really fun one because i can imagine it being genuinely useful in normal code but it's so fucking weird the way it's implemented

if you call type() with one argument, you get the type of the argument back

if you call type() with three arguments, the first of which is a string, the second is a collection (list, tuple, etc) of types, and the third is a mapping (dict, etc), it returns a class with the given name, inheriting from the given types, and with the given named values

one of these challenges wanted me to create a variable called Solution set to an object with a main method that printed "Hello World!"

Solution=type('',(),{'main':lambda*a:print('Hello World!')})()

@monorail I think this mostly makes sense to me, but what's up with the *a in 'main':lambda*a:print? Is that a multiplication? :psyduck:

@vaporeon_ @monorail I love python but lambda is python's horrible anonymous function syntax and I hate it

Follow

@vaporeon_ @monorail the syntax is lambda <arguments> : <return value>. The splat syntax is python's way of expressing variadac arguments--however many argument are provided to the function will be stored as a list in the name to the right of the splat.

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.