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):
Ïà¹ØÎĵµ£º
import sys
import os
import datetime
import time
class ArgsDealwith:
def arg_environment(self, args):
filepath = ('PYTHON_PATH', 'path')
for i in filepath:
&nbs ......
ÔÚ½²Êöfilter£¬mapºÍreduce֮ǰ£¬Ê×ÏȽéÉÜÒ»ÏÂÄäÃûº¯Êýlambda¡£
lambdaµÄʹÓ÷½·¨ÈçÏ£ºlambda [arg1[,arg2,arg3,...,argn]] : expression
ÀýÈ磺
>>> add = lambda x,y : x + y
>>> add ......
http://blog.chinaunix.net/u1/59571/showart_1901962.html
1. ÔÚPythonÖÐʹÓÃÖÐÎÄ
ÔÚPythonÖÐÓÐÁ½ÖÖĬÈϵÄ×Ö·û´®£ºstrºÍunicode¡£ÔÚPythonÖÐÒ»¶¨Òª×¢ÒâÇø·Ö“Unicode×Ö·û´®”ºÍ“unicode¶ÔÏó”µÄÇø±ð¡£ºóÃæËùÓеēunicode×Ö·û´®”Ö¸µÄ¶¼ÊÇpyt ......
×î½üÒòΪÑо¿Ò»¸ö¶«Î÷£¬²¢ÇÒÔںܾÃÒÔǰ¾ÍÏë°ÑpythonºÃºÃ¿´¿´¡£ÕýºÃÂú×ãÎ񵀼̮æÐÄ¡£ÎÒÿÌìÉϰà×öµÃÓÎÏ·¶¼ÊÇÓÃlua£¬Ò²ÊÇÒ»ÃźÜÇ¿´óµÄ½Å±¾ÓïÑÔ¡£¿ÉÄÜÎÒ¸üϲ»¶pythonµÄËõ½øÇø·ÖºÍÃæÏò¶ÔÏó°É¡£ ½ñÌìֻдһ¸ö¼òµ¥µÄÀý×Ó¡£Ò»¸ö¼òµ¥µÄpython½Å±¾£¬¾ÍÒ»¸öº¯Êý£¬ÓÃC/C++È¥µ÷Ó᣿ÉÄÜÕâÒ²ÊÇ×÷Ϊ³ÌÐòÀ´Ëµ×î¹ØÐĵÄÒ»¼þÊ¡£ËùÒÔÎÒµÄpytho ......
֮ǰѧϰµÚ¾ÅÕµÄÅÅÐòС½áµÄʱºò£¬¶Ôsort()ÅÅÐò·½·¨²»Àí½â£¬ÒòΪÀ¨ºÅÀïÃæ´øÁË×Ô¶¨ÒåµÄ±È½Ïº¯Êý¡£
ºóÀ´²éÊֲᣬ²Å·¢ÏÖsort()ÀïÃæ±¾À´¾Í´øÁËÕâÑùµÄ²ÎÊý¡£Äܹ»×Ô¶¨Òå±È½Ï·½·¨£¬È·ÊµºÜÁé»î¡£
²»½öÈç´Ë£¬ÔÚÍøÉϲ鵽һ¸ö²©¿Í£¬×÷Õß²»µ¥Í£ÁôÔÚÕâ±íÃæ£¬»¹²é¾¿ÁËsort()µÄÅÅÐòËã·¨£¬È·ÊµÓÐÒâ˼¡£
È«Îij¼ÈçÏ£º
http://blog.done ......