python - appending text to a global variable -


i having problems global variables in python; have defined global variable in method , trying append text method.

method1:

def method1():     global v     v="hi "     print v 

method2:

def method2():    print v # prints `hi`    v +="go home"    print v # doesn't append 

how call:

method1() method2() 

expected output hi go home, not getting expected output.

how can solve ? need append text in method2() , display it.

declare v global:

>>> def method1(): ...     global v ...     v="hi " ...  >>> def method2(): ...     global v ...     v +="go home" ...  >>> method1() >>> method2() >>> v 'hi go home' 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -