pythonѧϰ
4¡¢Tuples Ôª×é
Ôª×éºÍListsÏàËÆ£¬µ«ËüÊÇimmutable,³õʼ»¯ºó²»ÄܸıäÆäÄÚÈÝ£¬ÕâÔÚ³ÌÐòÖÐÓÐʱºòºÜÓÐÓ㬿ÉÒÔÓÃÀ´·ÀÖ¹¶¨ÒåµÄ±äÁ¿ÄÚÈݱ»ÒâÍâ¸Ä±ä¡£
5¡¢Files Îļþ
Îļþ²Ù×÷ºÍcÓïÑԱȽϽӽü£¬ÏÂÃæÖ»Í¨¹ý´úÂëÑÝʾ£º
>>> f = open('data.txt','w')
>>> f.write('mike\n')
>>> f.write('wolf\n')
>>> f.close()
>>> f = open('data.txt')
>>> bytes = f.read()
>>> bytes
'mike\nwolf\n'
>>> print bytes
mike
wolf
>>> bytes.split()
['mike', 'wolf']
>>> bytes
'mike\nwolf\n'
6¡¢ÆäËûÊý¾ÝÀàÐÍ
Set(¼¯ºÏ)£¬fixed prescion floating number (¹Ì¶¨¾«¶ÈµÄ¸¡µãÊý)£¬Boolean£¨²¼¶û±äÁ¿£©£¬placehold£¨Õ¼Î»·û£©µÈ¡£
ÏÂÃæ¿´ÏÂʹÓõÄһЩ´úÂ룺
>>> x = set([1, 2, 3,4])
>>> y = set([3,4, 5,6])
>>> x|y
set([1, 2, 3, 4, 5, 6])
>>> x+y
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
x+y
TypeError: unsupported operand type(s) for +: 'set' and 'set'
>>> x,y
(set([1, 2, 3, 4]), set([3, 4, 5, 6]))
>>> x&y
set([3, 4])
>>> x-y
set([1, 2])
>>> y-x
set([5, 6])
>>> import decimal
>>> d = decimal.Decimal('4.321')
>>> d
Decimal('4.321')
>>> 1>2
False
>>> 1<2
True
>>> None
>>> L = [None]*5
>>> L
[None, None, None, None, None]
>>>
PythonÖеÄÀàÐͼì²é´úÂ룺
>>> L
[None, None, None, None, None]
>>> type(L)
<type 'list'>
>>> type(type(L))
<type 'type'>
>>> if type(L)==type([]):
print('ÀàÐÍÏàͬ')
ÀàÐÍÏàͬ
>>> if type(L)==list: #ÓÃÀàÐÍÃû×Ö
print('ok')
ok
>>> if isinstance(L,list):
print('yes')
yes
>>>
7¡¢Óû§¶¨ÒåÀà user-defined class
>>> class worker:
def __init__(self, name, pay):
self.name = name
self.pay = pay
def lastname(self):
Ïà¹ØÎĵµ£º
#coding=utf-8
from newtest.wiki.models import WiKi
from django.template import loader, Context
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
def index(request, pagename=""):
"""ÏÔʾÕý³£Ò³Ã棬¶ÔÒ³ÃæµÄÎÄ×Ö×öÌØÊâµÄÁ´½Ó´¦Àí"""
......
import sys
import os
import datetime
import time
class ArgsDealwith:
def arg_environment(self, args):
filepath = ('PYTHON_PATH', 'path')
for i in filepath:
&nbs ......
ѧϰÁ˵ڰËÕº󣬽ôÂàÃܹĵĿªÊ¼µÚ¾ÅÕµÄѧϰ¡£
ѧϰÁË“Êý¾Ý½á¹¹²Ù×÷”£¬Ñ§Ï°ÁË“Îļþ²Ù×÷”¡£“Êý¾Ý½á¹¹²Ù×÷”»¹±È½ÏÓÐÒâ˼£¬¿´µÃ¶®¡£“Îļþ²Ù×÷”¾Í¿ªÊ¼Í·»è»èµÄ£¬ÏñÄÔ×Ó½øÁ˽¬ºý¡£
ºÃ²»ÈÝÒ׿´µ½“²Ù×÷³ÌÐò”£¬²Å·¢ÏÖ“²Ù×÷³ÌÐò”ÕâÒ»½ÚµÄÄÚÈݲ¢²»ÊÇÎÒËù ......
3¡¢Lists Êý¾ÝÀàÐÍ
ÔÚpythonÖУ¬listsÊÇÐòÁÐÈÝÆ÷£¬Ëü¿ÉÒÔÈÝÄÉÈκÎÀàÐ͵ĶÔÏ󡣺Ístrings²»Í¬£¬ListsÖ§³ÖÔµØÐÞ¸Ä(mutalbe in place),ͨ¹ýϱêÒýÓõķ½Ê½£¬¿ÉÒÔÐÞ¸ÄListsµÄÄÚÈÝ£¬ÈçpÊÇLists¶ÔÏó£¬ Ôò¿ÉÒÔͨ¹ýp[1] = '123'ÕâÖֵķ½Ê½¸Ä±äpµÄÄÚÈÝ¡£
ListsÊÇÐòÁÐÈÝÆ÷£¬Ö§³ÖÈκÎÐòÁÐ ......
http://www.cppblog.com/oosky/archive/2005/10/11/639.html
Lesson 1 ×¼±¸ºÃѧϰPythonµÄ»·¾³
Python µÄ¹Ù·½ÍøÖ·£º
www.python.org
µã»÷ÏÂÃæÁ¬½Ó¾Í¿ÉÒÔÖ±½ÓÏÂÔØÁË£¬ÕâÀïÖ»ÌṩÁËWindowsϵÄPython¡£
http://www.python.org/ftp/python/2.4.2/python-2.4.2.msi
linux°æ±¾µÄÎҾͲ»ËµÁË£¬ÒòΪÈç¹ûÄãÄܹ»Ê¹ÓÃlinux²¢°²×° ......