python »ù´¡
Python¿ìËÙÈëÃÅ
Ŀ¼
1. µÚÒ»Õ Python¿ìËÙÈëÃÅ
±¾ÕÂÊÇPythonµÄ¿ìËÙÈëÃÅ,ÔÚÕâÒ»Õ²¢²»Éæ¼° pythonµÄÌØÊâ¹æÔòºÍϸ½Ú,Ä¿±êÊÇͨ¹ýʾÀýʹ Äã¿ìËÙÁ˽âPythonÓïÑÔµÄÌØµã¡£±¾Õ¼òÒª½éÉÜÁ˱äÁ¿,±í´ïʽ,¿ØÖÆÁ÷,º¯ÊýÒÔ¼°ÊäÈë/Êä³öµÄ»ù±¾¸ÅÄî,ÔÚÕâÒ»Õ²»Éæ¼°PythonÓïÑԵĸ߼¶ÌØÐÔ¡£
1. ÔËÐÐPython
2. ±äÁ¿ºÍ±í´ïʽ
3. Ìõ¼þÓï¾ä
4. ÎļþÊäÈë/Êä³ö
5. ×Ö·û´®
6. ÁбíºÍÔª×é(Lists & Tuples)
7. Ñ»·
8. ×Öµä
9. º¯Êý
10. Àà
11. Òì³£
12. Ä£¿é
1.1ÔËÐÐpython
Python ³ÌÐòͨ¹ý½âÊÍÆ÷Ö´ÐС£Èç¹ûÄãµÄ»úÆ÷ÒѾװºÃÁËpython,¼òµ¥µÄÔÚÃüÁîÐмü
Èëpython¼´¿ÉÔËÐÐpython½âÊÍÆ÷¡£ÔÚ½âÊÍÆ÷ÔËÐеÄʱ,»áÓÐÒ»¸öÃüÁîÌáʾ·û >>>,
ÔÚÌáʾ·ûºó¼üÈëÄãµÄ³ÌÐòÓï¾ä,¼üÈëµÄÓï¾ä½«»áÁ¢¼´Ö´ÐС£ÔÚϱߵÄÀý×ÓÖÐ,ÎÒÃÇ
ÔÚ>>>Ìáʾ·ûºó±ß¼üÈë×î³£¼ûµÄÏÔʾ"Hello World"µÄÃüÁî:
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello world"
hello world
>>> print 'hello world'
hello world
³ÌÐòÒ²¿ÉÒÔÏñÏÂÃæÒ»Ñù·ÅÖÃÔÚÒ»¸öÎļþÖÐ,ÎÒʹÓÃvim±à¼Æ÷±à¼hello.py³ÌÐò¡£
ÔÚUNIXÏÂ,Äã¿ÉÒÔÔÚ³ÌÐòµÄÊ×ÐÐдÈë #! ħ·¨×Ö·û´® À´×Ô¶¯µ÷ÓÃpython½âÊÍÆ÷Ö´ÐÐÄã
µÄ½Å±¾¡£
#!/usr/bin/python
print "hello world"
È»ºóÔÚpythonÖÐÔËÐÐ
windyang@windyang-desktop:~$ python helloworld.py
hello world
PythonÔ´´úÂëÎļþʹÓÃ.pyºó׺.'#'±íʾעÊÍ(µ½ÐÐÄ©½áÊø)£¬µ±È»¶ÔÓÚÕâ¸öÎļþÄãÒ²¿ÉÒÔʹÓú¯Êýexecfile()À´ÔËÐÐÒ»¸ö±¨´æÔÚ´ÅÅÌÉϵijÌÐò
>>> execfile(&quo
Ïà¹ØÎĵµ£º
×ªÔØ×Ô£ºhttp://hi.baidu.com/myitlyj/blog/item/25586bd7088ba3dba044df6b.html
ÔÚ³ÌÐòÖÐʹÓÃÅäÖÃÎļþÀ´Áé»îµÄÅäÖÃһЩ²ÎÊýÊÇÒ»¼þºÜ³£¼ûµÄÊÂÇ飬ÅäÖÃÎļþµÄ½âÎö²¢²»¸´ÔÓ£¬ÔÚpythonÀï¸üÊÇÈç´Ë£¬ÔÚ¹Ù·½·¢²¼µÄ¿âÖоͰüº¬ÓÐ×öÕâ¼þÊÂÇéµÄ¿â£¬ÄǾÍÊÇConfigParser£¬ÕâÀï¼òµ¥µÄ×öһЩ½éÉÜ¡£
ConfigParser½âÎöµÄÅäÖÃÎļþµÄ¸ñÊ ......
int main()
{
int a[] = {1,2,3,4,5};
int i;
int * p = a;
for (p = a + 4, i = 0; i < 5; i++) {
printf("%d ",p[-i]);
}
return 0;
}
......
import sys, pygame, time
size = width, height = 700,700
fontColor = (0,0,255)
class walk:
'''This is a game about war.
Just like war 3.'''
def __init__(self):
'''Init the screen.
Get param and init the screen'''
#print ('this is init funnction') ......
while µÄÓ÷¨£º
while ºóÃæ¸úÌõ¼þ±í´ïʽ£¬(:)ºóÃæ¸úÓï¾ä¿é£¬Äã¿ÉÒÔÔÚÕâ¶ÎÓï¾ä¿éÀïÐÞ¸ÄÌõ¼þ±í´ïʽµÄijЩ±äÁ¿£¬µ±Ìõ¼þ±í´ïʽ Ϊ¼ÙµÄʱºòÍ˳öÑ»·¡£ÀýÈ磺
flag = 5
while flag > 0:
#ÕâÀïÊÇÄãµÄ´úÂë
flag -= 1
#if flag == 3: break
#if flag == 3: continue
print flag
µ±È»ÄãÒ²¿ÉÒÔÔÚÊʵ ......