>"But be on your guard so that your hearts are not wighted down with dissipation and drunkenness and the worries of this life, and that day close down upon you suddenly like a trap. For it will overtake all who live on the face of the whole earht. But staty alert at all times, praying that you may have strength to eacape all these things that must happen, and to stand before the Son of Man."
>ä½ ä»¬è¦è°¨æ
ï¼ææå è´ªé£éé
å¹¶ä»ççæèï¼ç´¯ä½ä½ 们çå¿ï¼é£æ¥åå°±å¦åç½ç½å¿½ç¶ä¸´å°ä½ 们ãå ä¸ºé£æ¥åè¦è¿æ ·ä¸´å°å
¨å°ä¸ä¸åå±
ä½ç人ãä½ ä»¬è¦æ¶æ¶åéï¼å¸¸å¸¸ç¥æ±ï¼æ¯ä½ 们è½éé¿è¿ä¸åè¦æ¥çäºï¼å¾ä»¥ç«ç«å¨äººåé¢åã(LUKE 21:34-36)
#è¯å¥(3)
循ç¯ï¼ä½ æé½å¨å
¶ä¸ã
æ¥ææ´è¿ï¼æè½¬æç§»ï¼æ 䏿¯å¾ªç¯ï¼çææ´è¿ï¼ååååï¼ä»æä¸ªè§åº¦çä¹é½æ¯å¾ªç¯ã
å¾ªç¯æ¯ç°å®çæ´»ä¸å¸¸è§çç°è±¡ã
ç¼ç¨è¯è¨å°±æ¯è¦è§£å³ç°å®é®é¢çï¼å æ¤ä¹å°ä¸äºè¦å¾ªç¯ã
##for循ç¯
å¨é«çº§ç¼ç¨è¯è¨ä¸ï¼å¤§å¤æ°é½æfor循ç¯ï¼for loopï¼ï¼å
³äºè¿ç§å¾ªç¯ï¼æåç¨[ç»´åºç¾ç§ä¸âfor loopâ](https://en.wikipedia.org/wiki/For_loop)ç说æï¼å¸®å©å¤§å®¶çè§£ã
>In computer science a for-loop (or simply for loop) is a programming language control statement for specifying iteration, which allows code to be executed repeatedly. The syntax of a for-loop is based on the heritage of the language and the prior programming languages it borrowed from, so programming languages that are descendants of or offshoots of a language that originally provided an iterator will often use the same keyword to name an iterator, e.g., descendants of ALGOL use "for", while descendants of Fortran use "do." There are other possibilities, for example COBOL which uses "PERFORM VARYING".
妿çä¸é¢çè±ææç¹é¾åº¦ï¼å¯ä»¥çä¸é¢çç¿»è¯ï¼å½ç¶æ¯å¾ççç¿»è¯ï¼ç»å¯¹è¾¾ä¸å°âä¿¡é
è¾¾âçå¢çï¼è½ç¶ä¸ç´è¿½æ±âå¾·èºå馨âã
>å¨è®¡ç®æºç§å¦ä¸forå¾ªç¯æ¯ç¼ç¨è¯è¨ä¸é对å¯è¿ä»£å¯¹è±¡çè¯å¥ï¼å®å
许代ç 被é夿§è¡ãfor循ç¯çè¯æ³æ¯å¨å¯¹åå²ä¸çç¼ç¨è¯è¨ç»§æ¿ååé´åºç¡ä¸å½¢æçï¼è¯¥è¯è¨åæ¥æè¿ä»£å¨ï¼å忥çç¼ç¨è¯è¨ä¹ç¨åæ ·çå
³é®è¯æ¥å®ç°è¿ä»£ï¼æ¯å¦ALGOLç³»ç使ç¨âforâï¼èFortanç³»ç使ç¨âdoâï¼ä¹æä¾å¤ï¼å¦COBOLç¨âPERFORM VARYINGâã
forå¾ªç¯æ¯ä»ALGOLé£éç»§æ¿è¿æ¥çãALGOLï¼ALGOrithmic Languageï¼æ¯ææ©çé«çº§ç¼ç¨è¯è¨ï¼å 乿²¡æä¹ä¸ï¼ï¼åæ¥çä¸å°é«çº§è¯è¨é½ç»§æ¿äºALGOLçæäºç¹æ§ï¼æ¯å¦PascalãAdaãCè¯è¨çï¼ä¹å
æ¬Pythonã
ç»´åºç¾ç§ä¸å¯¹æ¤æé常æ¸
æ°ç说æã
>The name for-loop comes from the English word for, which is used as the keyword in most programming languages to introduce a for-loop. The term in English dates to ALGOL 58 and was popularized in the influential later ALGOL 60; it is the direct translation of the earlier German für, used in Superplan (1949â1951) by Heinz Rutishauser, who also was involved in defining ALGOL 58 and ALGOL 60. The loop body is executed "for" the given values of the loop variable, though this is more explicit in the ALGOL version of the statement, in which a list of possible values and/or increments can be specified.
å¨ALGOLä¸ï¼å¾ªç¯çå
³é®è¯å°±æ¯ç¨forãæä»¥ï¼Pythonè¦ç»§æ¿è¿ä¸ªå
è£ä¼ ç»ï¼ä¹ç¨foræ¥å®ç°å¾ªç¯ã
äºæ¯æäºï¼forè¯å¥ã
å
¶åºæ¬ç»ææ¯ï¼
for 循ç¯è§åï¼
æä½è¯å¥
ä»è¿ä¸ªåºæ¬ç»æçï¼æçåifæ¡ä»¶è¯å¥ç±»ä¼¼çå°æ¹ï¼é½æåå·ï¼è¯å¥åé½è¦åä¸ªç©ºæ ¼ç¼©è¿ã
##ä»ä¾åä¸çè§£for循ç¯
ä¸é¢è¿ä¸ªä¾åä¼¼æ¾ç¸è¯ã
>>> hello = "world"
>>> for i in hello:
... print i #Python 3: print(i)
...
w
o
r
l
d
è¿ä¸ªä¾åä¸å®ç°çå°±æ¯for循ç¯ãä¸é¢åºä¸è§£çï¼
1. `hello = "world"`ï¼èµå¼è¯å¥ï¼å®ç°åé`hello`åå符串`"world"`ä¹é´çå¼ç¨å
³ç³»ã
2. `for i in hello:`ï¼`for`æ¯å起循ç¯çå
³é®è¯ï¼`i in hello`æ¯å¾ªç¯è§åï¼å符串类åç对象æ¯åºåç±»åï¼è½å¤ä»å·¦å°å³ä¸ä¸ªä¸ä¸ªå°æç
§ç´¢å¼è¯»åºæ¯ä¸ªå符ï¼äºæ¯åé`i`å°±æç
§ç´¢å¼é¡ºåºï¼ä»ç¬¬ä¸å符å¼å§ï¼ä¾æ¬¡è·å¾è¯¥å符çå¼ç¨ã
3. å½ `i="w"`çæ¶åï¼æ§è¡`print i`æè
`print(i)`ï¼æå°åºäºåæ¯wï¼ç¶å循ç¯ç¬¬äºæ¬¡ï¼è®© `i="e"`ï¼æ§è¡`print i`æè
`print(i)`ï¼æå°åºåæ¯eï¼â¦â¦ï¼å¦æ¤å¾ªç¯ä¸å»ï¼ä¸ç´å°æåä¸ä¸ªå符被æå°åºæ¥ï¼å¾ªç¯èªå¨ç»æã注æï¼æ¯æ¬¡æå°ä¹åï¼è¦æ¢è¡ã妿䏿³æ¢è¡ï¼æä¹åï¼åè§[ãè¯å¥(1)ã](./121.md)ä¸ç¸å
³å
容ã
å 为å¯ä»¥ä¹éè¿ä½¿ç¨ç´¢å¼ï¼å¾å°åºå对象çæä¸ªå
ç´ ãæä»¥ï¼è¿å¯ä»¥éè¿ä¸é¢çå¾ªç¯æ¹å¼å®ç°åæ ·ææï¼
>>> for i in range(len(hello)):
... print hello[i] #Python 3: print(hello[i])
...
w
o
r
l
d
å
¶å·¥ä½æ¹å¼æ¯ï¼
1. `len(hello)`å¾å°helloå¼ç¨çå符串çé¿åº¦ï¼ä¸º5
2. `range(len(hello)`ï¼å°±æ¯`range(5)`,ä¹å°±æ¯`[0, 1, 2, 3, 4]`ï¼å¯¹åºè¿`"world"`æ¯ä¸ªåæ¯ç´¢å¼ãè¿éåºç¨äºä¸ä¸ªæ°ç彿°`range()`ï¼å
³äºå®çç¨æ³ï¼ç»§ç»é
读ï¼å°±è½çå°äºã
3. `for i in range(len(hello))`ï¼å°±ç¸å½äº`for i in [0,1,2,3,4]`ï¼è®©`i`便¬¡å¾å°å表ä¸çå个å¼ãå½`i=0`æ¶ï¼æå°`hello[0]`ï¼ä¹å°±æ¯ç¬¬ä¸ä¸ªå符ãç¶å顺åºå¾ªç¯ä¸å»ï¼ç´å°æåä¸ä¸ª`i=4`为æ¢ã
以ä¸ç循ç¯ä¸¾ä¾ä¸ï¼æ¾ç¤ºäºå¯¹å符串çåç¬¦ä¾æ¬¡è·åï¼ä¹æ¶åäºåè¡¨ï¼æè§ä¸è¿ç¾åã
é£å¥½ï¼çä¸é¢å¯¹å表ç循ç¯ï¼
>>> ls_line = ['Hello', 'I am qiwsir', 'Welcome you', '']
>>> for word in ls_line:
... print word #Python 3: print(word)
...
Hello
I am qiwsir
Welcome you
>>> for i in range(len(ls_line)):
... print ls_line[i] #Python 3: print(ls_line[i])
...
Hello
I am qiwsir
Welcome you
以ä¸ä¸¤ä¸ªä¾åä¸ï¼æ¯å°for循ç¯ç¨äºå符串ååè¡¨ï¼æ¤å¤ï¼è¿å¯ä»¥ç¨äºåå
¸ãå
ç»ãä¾å¦ï¼
>>> d = dict([("website", "www.itdiffer.com"), ("lang", "python"), ("author", "laoqi")])
>>> d
{'website': 'www.itdiffer.com', 'lang': 'python', 'author': 'laoqi'}
>>> for k in d:
print k #Python 3: print(k)
è¾åºç»ææ¯ï¼
website
lang
author
注æå°ï¼ä¸é¢ç循ç¯ï¼å
¶å®æ¯è¯»åäºåå
¸çkeyãå¨åå
¸ä¸ï¼æä¸ä¸ªæ¹æ³ï¼`dict.keys()`ï¼å¾å°çæ¯åå
¸keyå表ã
>>> for k in d.keys():
print k #Python 3: print(k)
website
lang
author
è¿ç§å¾ªç¯æ¹æ³åä¸é¢çå¾ªç¯æ¹æ³ï¼ç»ææ¯ä¸æ ·çï¼ä½æ¯ï¼è¿ç§æ¹æ³å¹¶ä¸æå¡ï¼ä»¥ä¸ºå®å¨æ§è¡é度ä¸è¡¨ç°æ¬ ä½³ã
妿è¦è·å¾åå
¸çvalueæä¹åï¼ä¸è¦å¿è®°`dict.values()`æ¹æ³ã读è
å¯ä»¥èªè¡æµè¯ä¸çªã
é¤äºå¯ä»¥åç¬è·å¾keyæè
valueç循ç¯ä¹å¤ï¼è¿å¯ä»¥è¿ä¹åï¼
>>> for k, v in d.items():
print k + "-->" + v #Python 3: print(k+"-->"+v)
website-->www.itdiffer.com
lang-->python
author-->laoqi
å¨å·¥ç¨å®è·µä¸ï¼ä½ ä¸å®ä¼éå°é常大çåå
¸ãç¨ä¸é¢çæ¹æ³ï¼è¦æææçå
容é½è¯»å
¥å
åï¼å
åä¸è¥¿å¤äºï¼å¯è½ä¼åºéº»ç¦ã为æ¤ï¼Python䏿ä¾äºå¦å¤çæ¹æ³ã
>>> for k,v in d.iteritems(): #注æï¼ä»
å¨Python2ä¸å¯ç¨ï¼Python 3ä¸å·²ç»åäºä¼åï¼d.item()峿åçåè½ã
print k + "-->" + v
website-->www.itdiffer.com
lang-->python
author-->laoqi
è¿éæ¯å¾ªç¯ä¸ä¸ªè¿ä»£å¨ï¼è¿ä»£å¨å¨å¾ªç¯ä¸æå¾å¤ä¼å¿ãé¤äºåæç`dict.iteritems()`ä¹å¤ï¼è¿æ`dict.itervalues()`ï¼`dict.iterkeys()`ä¾ä½ éç¨ï¼ä»¥ä¸ä¸ä¸ª`dict.iter*`é½åªç¨å¨Python 2ä¸ï¼Python 3ä¸å·²ç»ä¸éè¦äºï¼ã
>>> d.iteritems() #注æï¼ä»
å¨Python2ä¸å¯ç¨ã