python 3.x - why is the function code not working -


Trying to get

function call but I can not get it to print. Please help here this code is:

  def foo (): name = input ('> & gt;') Less (). Split () for the item in the name: if name == foo: ('Foo here!') Else: bar (def define): name = input ('> & gt;') Less (). Split () for the name in the name: if name == bar: print ('bar here!') Def start (print: 'Welcome home') name = input foo () Start ()   

both print ('foo here!') and print (' Bar here! ') was not executed because Boolean expression name == foo and names == times is evaluated on the wrong in most cases. For example, under the definition foo () , the first element of name == foo , name in Boolean expression foo . The foo object functions foo () (usually used for debugging purposes) gives the corresponding string representation that you can actually try foo ( ) Can print by typing print (foo) and list name in foo () (my case In its & lt; function fu 0x7fad58f35d40 & gt; - this will probably differ on your machine). This will evaluate name == foo and hence the result will be executed by the print ('foo here!') . It is being said that ,:

Enter image details here

< P> The first element in your name list is assigned to the item variable, then the body of the loop is executed. After executing the body, the second element in the list is specified in the name to the variable item before the body of the loop is re-implemented. This process continues until there is no other element in the name list. Now to execute print ('foo here!') for the order, the Boolean expression must be correctly evaluated in your statement

Here is an example where Print ('foo here!') Will execute when the user foo will run after running the program.

  def foo (): name = input ('> gt; & gt;') Less (). For item in the split () name: if item == 'foo': print ('foo here!') Else: bar () def bar (): name = input ('> gt; & gt;') Name for item (lower) Split (): If the item == 'bar': print ('bar here!') Print ('welcome home') Foo ()  

foo () , the first element of the list is compared with name foo, thus condition if name == 'foo' is found here is a sample of execution:

  [fairs @ arch python] $ ./foobar.py welcome home & gt; & Gt; Foo foo here!  

Comments