Skip to content
Advertisement

Can someone explain me how this programm with tkinter works? [closed]

Code:

JavaScript

Can someone explain how these loops work in this code? Would be very grateful, I’m a little confused right now.

Advertisement

Answer

Basically, the % is part of basic math and lambda is often called as the anonymous function, because it has no particular name.

So to begin with %:

JavaScript

Look at the example above, %, known as the modulo operator, means it will return the remainder while doing a fraction, in the example while doing 5÷2, it returns the remainder 1. Similarly, while doing 8÷2 it returns the remainder of the fraction, 1. Check here for more

Now about lambda, it’s an easy and very useful function, like a one-liner function. The syntax is lambda <parameters>:<expression>:

JavaScript

Here your assigning i to be a parameter x and k to be a parameter y, and passing it on to the function as arguments. With tkinter it allows you to pass arguments for a function. Here it’s more like your creating a new function(with lambda) that passes the arguments on to the old function created. Check here for more

As I’ve mentioned, without loop it could also be:

JavaScript

While your doing a for loop you want to hold the values from the for loop onto the function and that is why you use the first lambda expression and not the second one, if there was no for loop latter one would also work.

This is just for you to understand the basics, to understand better, you will have to google more about it and practice with implementation. This is just what I understood of modulo and lambdas, do correct me if I’m wrong.

Advertisement