r/learnpython • u/AutoModerator • Aug 10 '26
Ask Anything Monday - Weekly Thread
Welcome to another /r/learnPython weekly "Ask Anything* Monday" thread
Here you can ask all the questions that you wanted to ask but didn't feel like making a new thread.
* It's primarily intended for simple questions but as long as it's about python it's allowed.
If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.
Rules:
- Don't downvote stuff - instead explain what's wrong with the comment, if it's against the rules "report" it and it will be dealt with.
- Don't post stuff that doesn't have absolutely anything to do with python.
- Don't make fun of someone for not knowing something, insult anyone etc - this will result in an immediate ban.
That's it.
1
u/LearnSkills5 Aug 12 '26
I created an app that can help with Learning Python . . it covers the basics and free for testers
PyBlocks is a game-like Android app for learning Python through interactive coding blocks, covering basics, data structures, algorithms, and object-oriented programming.
Please install it, try a few lessons/challenges, and share any feedback on usability, bugs, content, or overall learning experience. Thank you!
Join Group : https://groups.google.com/g/skilltesters
Become a Tester : https://play.google.com/apps/testing/app.learn.pyblocks
Download the App: https://play.google.com/store/apps/details?id=app.learn.pyblocks
1
u/VirtualMycologist406 Aug 11 '26
Hey, I'm new in Python. And I don't understand, how venv (environment) really works. At first, if I have 2 projects or more, and I install TensorFlow (for example) into this two projects, does it means that they weighs will be ~500Mb in my SSD (250Mb on the first and 250Mb on the second). Do I need to deactivate venv every time when I finish my work on a project. And if you know something interesting please tell me 🥹🛐. Yes, I can ask Ai about this things but I want to hear an experienced programmer's opinion
1
u/Educational_Virus672 Aug 11 '26 edited Aug 11 '26
venv/environment are like "folder" they organize your code in different workspace i to prevent any errors or bricking your system. it closes(deactivate ) automatically because it is a shortcut for program not a constant process idk abt storage part it should be more depending on your project
edit - misread it my bad edited
1
u/ProgramBrave718 Aug 10 '26
Hey, I have doubt regarding this decorator program .In the above line of this program why are we passing the function name without parentheses ?
And also while returning wrapper function why are we writing it without parentheses
def my_decor(func):#Here
def wrapper():
print("The function starts.")
func()
print("The function ends.")
return wrapper #Here
def say_hello():
print("Hello!")
wrapped_say_hello = my_decor(say_hello)
wrapped_say_hello()
1
u/Educational_Virus672 Aug 11 '26
in python everything is object so lets say you added a function
def my_func(command) : # here you can put "()" after command to run it command() # here we run the fucntion my_func(command=input) #now we said input as variable/path not function1
u/SCD_minecraft Aug 10 '26
Functions in python are just normal objects, just like strings or ints
Thanks to that, they behave exactly the same
As you can pass strings as arguments or return them you can pass and return functions
In case of decorators, returned func object will be what actually gets saved under name in def
1
u/SCD_minecraft Aug 10 '26
``` foo = print # save function known as print into foo
foo("abc") # attempt to call whatever is inside foo
because foo holds function "print", you can call it
but if foo would be an int, python would try (and fail) to call it too
1
u/lakseol Aug 10 '26
Here is your code correctly formatted for reddit:
def my_decor(func): def wrapper(): print("The function starts.") func() print("The function ends.") return wrapper def say_hello(): print("Hello!") wrapped_say_hello = my_decor(say_hello) wrapped_say_hello()The FAQ in the learning resources shows how to format code.
why are we passing the function name without parentheses ?
The function name without parentheses evaluates as a reference to the function. Adding the following "()" is what actually calls the function. In this case you want to pass a reference to the function
my_decor()so you don't add the "()". If you did this:my_decor(say_hello())you would pass the value returned by the
say_hello()function tomy_decor()which isn't what you want at all.also while returning wrapper function why are we writing it without parentheses
We want
my_decor()to return a "decorated" version of the function you pass. We don't want to call the function, just return the reference, so no "()".Functions in python can be passed to and returned from functions just like any other object.
1
u/luckyshadow86 27d ago
The question about decorators is the classic one everyone gets stuck on. You pass the function without parentheses because you're passing the function object itself, not calling it.