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):
3. Dictionaries ×ÖµäÀàÐÍ
PythonÖУ¬×ÖµäÀàÐͲ¢²»ÊÇ˳ÐòÈÝÆ÷£¬¶øÀàËÆc++ÖеĹØÁªÈÝÆ÷(map)£¬DictionariesÖд洢µÄÊǼü/Öµ ¶Ô£¬ºÍmap²»Í¬µÄÊÇ£¬PythonµÄDictionariesÖпÉÒÔ´æÈÎÒâ¶ÔÏóÀàÐÍ¡£DictionariesÀàÐÍÒ²ÊǿɱäµÄ£¬ºÍListsÒ»Ñù£¬¿ÉÒÔÔµØÐ޸ģ¨Í¨¹ýϱêÐ޸ģ©¡£
ÏÂÃæͨ ......