python for in range
ÒÔǰûÓÐд¹ýpython½Å±¾£¬ÓÚÊÇÕÒÁËÒ»¸ö¼òÒ׵Ľ̳̹ýÁËÒ»±éÓÚÊǾÍÊǸÉÁË¡£
ÕâÁ½Ìì²âÊÔmysql archiveÒýÇæµÄÐÔÄÜ£¬ÓÚÊÇÓÃpythonÏòarchive±íÖвåÈë10ÒÚÌõÊý¾Ý£¬python´óÖÂÊÇÈçÏÂдµÄ£º
for i in range(0,100000000)
insert into ....
½á¹ûÖ´ÐÐÖ®ºóϵͳ¾ÍËÀ»úÁË£¬ÇóÖú“ΰ¸ç”£¬×îºó·¢ÏÖÔÙÖ´Ðнű¾µÄʱºò£¬for in range½«ÄÚ´æ³ÔÍêÁË£¬È¥pythonµÄÎĵµÖÐËÑË÷ÁËһϣ¬µÃµ½ÏÂÃæµÄ£º
range([start], stop[, step])
This is a versatile function to create lists containing arithmetic progressions. It is most often used in for loops.
ÔÀ´pythonÖ±½Ó¸ø´´½¨ÁËÒ»¸ölistÀïÃæ°üº¬ÁË10ÒÚ¸öÕûÊý£¬10ÒÚ*4byte=40 000 0000byte=400g£¬Ö±½Ó¾Í°ÑϵͳÄÚ´æ¸ø³Ô¸ÉÁË
Ð޸ijÉwhile i<100000000Ö®ºó¾ÍokÁË£¬¿´À´“ÏÝÚ唺ܶ࣬ÒÔºóµÃСÐÄÁË£¬¸Ðл“ΰ¸ç”£¬¿´À´½ª»¹ÊÇÀϵÄÀ±£¬¶øÇÒÀ±¶àÁË¡£
Ïà¹ØÎĵµ£º
1¡£
myCoolVariable="some_string"
os.system("echo myCoolVariable")
2.
>>> os.system('echo "asdg"')
asdg
0
>>> os.system("echo 'asdgwere'")
asdgwere
0
3.
$ python
>>>hamburger="potato"
>>>import os
>>>os.system("echo 'hamburger'")
potato
0
......
½ñÌìѧϰÁËÒ»ÏÂPythonµÄ²Ù×÷·ûÖØÔØ£¬×ܽáÁ˼¸µã±È½ÏÉñÆæµÄ¶«¶«£º
------------------------------------------------------------------------------------------------------------
¹ØÓÚiter£º
Technically, iteration contexts work by calling the iter built-in function to try to
find an _ _iter_ _ method, whi ......
1.1. Óï·¨
1.1.1. if
>>> x=int(raw_input("please enter an integer:"))
please enter an integer:-8
>>> if x<0:
... print 'negative'
... elif x==0:
... print 'zero'
... else:
... print 'positive'
...
negative
ÕâÀïÓм¸¸ö֪ʶµãÐèÒªÌáÐÑ£º
1¡£ºÍ ......
µ±ÒªÊ¹º¯Êý½ÓÊÕÔª×é»ò×ÖµäÐÎʽµÄ²ÎÊýµÄʱºò£¬ÓÐÒ»ÖÖÌØÊâµÄ·½·¨£¬Ëü·Ö±ðʹÓÃ*ºÍ**ǰ׺¡£ÕâÖÖ·½·¨ÔÚº¯ÊýÐèÒª»ñÈ¡¿É±äÊýÁ¿µÄ²ÎÊýµÄʱºòÌرðÓÐÓá£
>>> def powersum(power, *args):
... '''Return the sum of each argument raised to specified power.'''
... ......
PythonÊÇÄ¿Ç°¹ã·ºÊ¹ÓõÄÒ»ÃŶ¯Ì¬ÓïÑÔ£¬ÀàËÆJava£¬Ô´´úÂë±ØÐëÊ×ÏÈÓɱàÒëÆ÷ת»»³É×Ö½ÚÂ루byte code£©£¬È»ºóÔÙÓɽâÊÍÆ÷À´Ö´ÐÐ×Ö½ÚÂë¡£ÓëJava²»Í¬µÄÊÇ£¬PythonµÄ±àÒëÆ÷ºÍ½âÊÍÆ÷¶¼ÊÇÒ»¸ö³ÌÐò¡£Òò´Ë£¬Ô´´úÂëÒ²¿ÉÒÔÖ±½Ó½»¸øÕâ¸ö±àÒëÆ÷£¯½âÊÍÆ÷À´Ö´ÐС£
ʹÓÃPython±àд³ÌÐò£¬Äã²»ÐèÒªÔ¤ÏÈÉùÃ÷ºÃ±äÁ¿µÄÀàÐÍ£¬ÒòΪPythonÖбäÁ¿µÄÀ ......