Can someone explain some simple python concepts to me? -
i've been working through "learn python hard way" , far it's going pretty well, have couple of questions:
the_count = [1, 2, 3, 4, 5] fruits = ['apples', 'oranges', 'pears', 'apricots'] alter = [1, 'pennies', 2, 'dimes', 3, 'quarters'] # first kind of for-loop goes through list number in the_count: print "this count %d" % number # same above fruit in fruits: print "a fruit of type: %s" % fruit # can go through mixed lists # notice have utilize %r since don't know what's in in change: print "i got %r" %
in these loops, respectively, matter words "number", "fruit" , "i" are? feels in python needs defined never "defined" number if makes sense. i'm not sure how word question correctly =/
no, doesn't matter utilize names. can pick name wish these identifiers, long valid python identifiers.
name them foo
, bar
, vladiwostok
, whatever. is thought pick name little more descriptive of course, fruit
or number
great names in context used.
in case, of te next equivalent:
for foo in fruits: print "a fruit of type: %s" % foo bar in fruits: print "a fruit of type: %s" % bar vladivostok in fruits: print "a fruit of type: %s" % vladivostok
python
No comments:
Post a Comment