+ 2
Certain functions being assigned to variables
Why are some functions like so my_file = open(“my.file”,”r”) assigned to variables? I thought about this when looking at the Pygame module, as it has a certain function to create a surface that was put in an example like this: Win = pygame.display.set_mode((500,500)) I don’t know why I brought that up, but you hopefully get what I mean.
6 Respostas
+ 1
Because they return a value. Then you can assign the returned value to a variable-in other languages- of the same type.
+ 1
so what would be the value of the first example? The contents of the file?
+ 1
You should check what open() returns and what functionality is available to that object.
+ 1
so it is the contents of the file
+ 1
But it is not just an string. Its an object with some methods contained within, so that you can do things with it.
+ 1
ohh ok, thank you!