Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

´ô´ôµÄPython ±Ê¼Ç


һЩ×ۺϵÄÐÅÏ¢
Python
ÀËõ½øºÜÖØÒª¡£Ã»ÓмâÀ¨ºÅ²»Òª½ô£¬

Python
¸ù¾ÝËõ½øÀ´·Ö¸îÓï¾ä¿é¡£
²ÎÊý²»ÐèÒª¶¨Ò壬¿ÉÒÔÖ±½ÓʹÓá£
Help(var)
²é¿´
var
µÄ°ïÖú¡£
Var
¿ÉÒÔΪÈκζ«Î÷£¬º¯Êý£¬Ä£¿é£¬Àà¡£
Python
ÖеÄ×Ö·û´®ÊDz»¿É±äµÄ¡£
Pass 
±íʾ¿ÕÓï¾ä¿é¡£
# ×¢ÊÍ
 
String
r‘I’m a string’
×ÔÈ»×Ö·û´®£¬²»½øÐÐתÒå¡£
‘I’m a string’ 
תÒå×Ö·û´®¡£
ÓÃ
+
¿ÉÁ¬½Ó×Ö·û´®
target = today + os.sep
+ now + '_' + \        
# \
ÓÃÀ´Á¬½Ó»»ÐеÄ×Ö·û´®
       
comment.replace(' ', '_') + '.zip'
 
º¯Êý
º¯ÊýµÄ¶¨Ò壺
Def function():  
     

DocString
'''Prints the maximum
of two numbers.
The two values must be integers.'''
¾ÍÊǸö×¢ÊÍ¡£¡£¡£µ«ÊÇ¿ÉÒÔͨ¹ýº¯ÊýÃû
.__doc__
À´Êä³ö¡£
help()
Ò²¿ÉÒԴﵽͬÑùµÄ×÷Óá£
 
Ä£¿éÏà¹Ø²Ù×÷
import moduleName –
ÒýÈë
moduleName
Ä£¿é£¬

Ö»Òª¸ÃÄ£¿éÔÚ
python
ϵͳ·¾¶Ï¡£
sys
Ä£¿é°üº¬ÁËÓë
Python
½âÊÍÆ÷ºÍËüµÄ»·¾³Óйصĺ¯Êý¡£
sys.argv
ÖаüÀ¨ÁËÎļþÃû¼°²ÎÊý¡£
sys.path
Öаüº¬ÊäÈëÄ£¿éµÄĿ¼ÃûÁбí
dir(ModuleName)
ö¾ÙÄ£¿éÖеÄËùÓÐÊôÐÔ£¬²ÎÊýΪ¿Õʱ·µ»Øµ±Ç°Ä£¿éµÄËùÓÐÊôÐÔ£¬ÊäÈëµÄÄ£¿é±ØÎªµ±Ç°Ä£¿éÊôÐÔÁбíµÄÒ»Ô±¡£
*
¿ÉÒÔÖ»µ¥¶ÀÔËÐÐÄ£¿éŶ
=v=
 
pyc
Îļþ
×Ö½Ú±àÒëµÄÎļþ¡£ÓÃÓÚʹģ¿éÊäÈë¸ü¼Ó¿ì½Ý¡£ÓëÆ½Ì¨Î޹ء£
 
__name__
ÅжÏÊÇ·ñÊÇÖ÷Ä£¿é
if __name__ ==
'__main__':
 
Áбí
List
list = [a,b,c]
len(list)        
ÁÐ±í³¤¶È
list.sort()      
ÁбíÅÅÐò
list.append(t)   
Áбíĩβ׷¼Ó


 
Ôª×é
Tuple
tuple = (a,b,c)
Ôª×éºÍÁбíÊ®·ÖÀàËÆ£¬Ö»²»¹ýÔª×éºÍ×Ö·û´®Ò»ÑùÊDz»¿É±äµÄ£¬¼´Äã²»ÄÜÐÞ¸ÄÔª×é¡£
³£ÓÃÓÚÊä³ö
print '%s is %d years
old' % (name, age)
 
Dict
ͬ
map
 
ÐòÁÐ
sequence
seq = [a,b,c,d,e]
ÓëÆäËû¼¸ÖÖÈÝÆ÷µÄ²»Í¬ÊÇË÷ÒýºÍÇÐÆ¬¡£
Ë÷Òý£ºµÃµ½Ò»¸öÌØ¶¨ÏîÄ¿
     
seq[2]
ÇÐÆ¬£º¿ÉÒԵõ


Ïà¹ØÎĵµ£º

¶¯Ì¬ÓïÑÔÖ®Î壺PythonÓïÑÔÓëÉè¼ÆÄ£Ê½

 Éè¼ÆÄ£Ê½ÊÇÒ»¸ö³éÏó²ã´Î£¬ÃèÊöÁËÔÚÒ»¸öÌØ¶¨µÄ»·¾³ÖÐÓÃÀ´½â¾öÒ»°ãÉè¼ÆÎÊÌâµÄ¶ÔÏóºÍÀàÖ®¼äµÄ½»»¥¹ØÏµ£¬ÆäÖ÷ҪĿµÄÊdzä·ÖÀûÓÃÓïÑÔµÄÌØÐÔ£¬Éè¼Æ¿É¸´Óõġ¢Äܹ»ÊÊÓ¦ÐèÇó±ä¸üµÄÈí¼þ[9]¡£Éè¼ÆÄ£Ê½ÊÇÒ»ÖÖÉè¼ÆË¼Ï룬ÓïÑÔÊÇʵÏÖ˼ÏëµÄ¹¤¾ß¡£Òò´Ë£¬²»Í¬ÓïÑÔµÄÌØÐÔÓ°ÏìÁËÉè¼ÆÄ£Ê½µÄʵÏÖ£¬ÓÐЩÓïÑÔ¸üÈÝÒ×ʵÏÖÉè¼ÆÄ£Ê½£¬¶øÓÐЩÓïÑÔÔ ......

pythonϵÄweb¿ª·¢¿ò¼Ü Django,djangoÄ£°åµÄʹÓÃ

Ä£°åÊǼòµ¥µÄÎı¾Îļþ£¬Ëü¿ÉÒÔÊÇhtml¸ñʽ»òÊÇxml,csvµÈ¸ñʽµÄ
Ä£°å°üÀ¨±äÁ¿£¬À¨Ëü»á±»ÖµËùÌæ´úµ±ÔËÐÐʱ£¬ÒÔ¼°±êÇ©Ëü¿ØÖÆÄ£°åµÄÂß¼­ÔËËãÈçif,elseµÈ
ÏÂÃæÊÇÒ»¸ö¼òµ¥µÄÄ£°å£¬ÎÒÃǽ«»á¶ÔËü×öÏêϸµÄ˵Ã÷
{% extends "base_generic.html" %}
{% block title %}{{ section.title }}{% endblock %}
{% block content %}
< ......

pythonϵÄweb¿ª·¢¿ò¼Ü Django,½¨Á¢Ä£ÐÍ

Òª´´½¨ÄãµÄapp£¨½«djangoÅäÖõ½»·¾³±äÁ¿Ï£©
python manage.py startapp polls
ËüÃǽ«»á´´½¨Ò»¸öpollsÎļþ¼Ð£¬ÀïÃæµÄÄÚÈÝÊÇ£º
¡¡¡¡polls/
¡¡¡¡¡¡¡¡__init__.py
¡¡¡¡¡¡¡¡models.py
¡¡¡¡¡¡¡¡views.py
Õâ¸öĿ¼½á¹¹¾ÍÊÇappÓ¦ÓóÌÐò¡£
±àдÊý¾Ý¿âWebÓ¦ÓóÌÐòµÄµÚÒ»²½ÊǶ¨ÒåÄãµÄÄ£ÐͲ㗗»ù±¾ÉϾÍÊÇÄãµÄÊý¾Ý¿ ......

PythonÈÕÆÚºÍ×Ö·û´®µÄ»¥×ª

ÓõķֱðÊÇtimeºÍdatetimeº¯Êý
'''
Created on 2009-9-2
@author: jiangqh
'''
import time,datetime
# date to str
print time.strftime("%Y-%m-%d %X", time.localtime())
#str to date
t = time.strptime("2009 - 08 - 08", "%Y - %m - %d")
y,m,d = t[0:3]
print datetime.datetime(y,m,d)

Êä³öµ±Ç°Ê±¼ä ......

¹ØÓÚPythonÖÐÒ»Öֻص÷·½Ê½µÄʵÏÖ

#¹ØÓڻص÷¹¦ÄܵIJâÊÔ
#FunctorÊÇÕâÖֻص÷¹¦ÄܵĹؼü¶ÔÏó
class Functor:
    """Simple functor class."""
    def __init__( self, fn, *args ):
        self.fn = fn
        ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ