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!')
andprint (' Bar here! ')
was not executed because Boolean expressionname == foo
andnames == times
is evaluated on the wrong in most cases. For example, under the definitionfoo ()
, the first element ofname == foo
,name
in Boolean expressionfoo
. Thefoo
object functionsfoo ()
(usually used for debugging purposes) gives the corresponding string representation that you can actually tryfoo ( ) Can print
by typingprint (foo)
andlist name
infoo ()
(my case In its& lt; function fu 0x7fad58f35d40 & gt;
- this will probably differ on your machine). This will evaluatename == foo
and hence the result will be executed by theprint ('foo here!')
. It is being said that ,:< P> The first element in your
name
list is assigned to theitem
variable, then the body of the loop is executed. After executing the body, the second element in the list is specified in thename
to the variableitem
before the body of the loop is re-implemented. This process continues until there is no other element in thename
list. Now to executeprint ('foo here!')
for the order, the Boolean expression must be correctly evaluated in your statementHere 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 conditionif name == 'foo'
is found here is a sample of execution:[fairs @ arch python] $ ./foobar.py welcome home & gt; & Gt; Foo foo here!
Comments
Post a Comment