Exercise 41: Learning to talk about object-oriented

I’m doing exercise 41, to be honest I’m very confused. I don’t know if it’s because I’ve been watching the damn thing for hours, if my brain is blown up, or what ?

I have passed the following content in the previous chapters, but for some reason, this is not translated to me in English.

PHRASE_FIRST = False 
if len(sys.argv) == 2 and sys.argv[1] == "english":
PHRASE_FIRST = True

I think it The statement is, if “phrase_first” is false, please read the list, if “phrase_first” is true, then read the English list? I have no idea? I think this is the midline and it really messed me up.

I need English decomposition to get me back on track.

No, the code sets PHRASE_FIRST to False.

Then test the sys.argv list; if the list There are 2 values ​​in and the second value is equal to the string “english”, then PHRASE_FIRST will bounce to True.

sys.argv is the command line parameter list; sys.argv[0] is the script Name, any additional elements in the list are strings passed in the command line:

python script.py foo bar

变< /p>

['script.py','foo','bar']

In sys.argv. In this case, if you run Script:

python script.py english

Then PHRASE_FIRST is set to True, otherwise it remains False.

I’m practicing 41. To be honest, I’m very confused. I don’t know if it’s because I’ve watched the damn thing for hours, if my brain is blown up, or what?

I have passed the following content in the previous chapters, but for some reason, this is not translated to me in English.

PHRASE_FIRST = False 
if len(sys.argv) == 2 and sys.argv[1] == "english":
PHRASE_FIRST = True

I think it The statement is, if “phrase_first” is false, please read the list, if “phrase_first” is true, then read the English list? I have no idea? I think this is the midline and it really messed me up.

I need English decomposition to get me back on track.

No, the code sets PHRASE_FIRST to False.

Then test the sys.argv list; if there are 2 values ​​in the list, and the second value is equal to String “english”, then PHRASE_FIRST will bounce to True.

sys.argv is the command line parameter list; sys.argv[0] is the name of the script, and any extra elements in the list are in The string passed in the command line:

python script.py foo bar

change

['script.py','foo','bar']

In sys.argv. In this case, if you run the script:

python script.py english

Then PHRASE_FIRST is set to True, otherwise it remains False.

Leave a Comment

Your email address will not be published.