Confused about an if statement in Learn Python the Hard Way ex41? -


i've been working through learn python hard way, , i'm having trouble understanding what's happening in part of code example 41 (full code @ http://learnpythonthehardway.org/book/ex41.html).

phrase_first = false if len(sys.argv) == 2 , sys.argv[1] == "english":     phrase_first = true 

i assume part has switching modes in game, english code, i'm missing how that. know len() function measures length, i'm confused sys.argv in situation, , why have equal 2, , 1 doing sys.argv[1].

thank help.

the len function measure length. in case measuring length of list (or called array).

the sys.argv represents list of strings passed in via command line arguments. here documentation on http://docs.python.org/2/library/sys.html

an example command line:

python learning.py 1 2 

this have total of 3 arguments passed sys.argv. arguments learning.py, 1 , 2 strings

the code,

sys.argv[1] 

is retrieving whatever stored @ index 1 sys.argv list. example above, return string 'one'. important remember python lists 0 indexed. first element of non empty list index 0.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -