I have a code like this:
>>> def enterText(value):
command = input ("enter text: ")
value = command
>>> def start():
text = ""
enterText(text)
print ("you entered: "+str(text))
I have tied a lot of things but I can’t seem to figure it out. I’m new to Python, can help me pass a string through functions? Thanks!
Strings in Python are immutable. You need to return the string from
enterText()so you can use it withinstart().A given string object cannot be changed. When you call
enterText(text),valuewill refer to the empty string object created withinstart().Assigning to
valuethen rebinds the variable, i.e. it connects the name “value” with the object referenced by the right-hand side of the assignment. An assignment to a plain variable does not modify an object.The
textvariable, however, will continue to refer to the empty string until you assign totextagain. But since you don’t do that, it can’t work.