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):
Ïà¹ØÎĵµ£º
¿Í»§¸øÒ»¶ÑͼƬҪ´«µ½ºǫ́£¬Í¼Æ¬Ì«´óÁË£¬ÉϰÙÕÅͼÓÃphotoshop¸ÄÌ«Âý£¬¾ÍÏëµ½ÓÃpythonд¸ö¼òµ¥µÄÅú´¦Àí¡£¹¦Äܼòµ¥¾ÍÊǰÑÔͼ°´±ÈÀýËõС£¬´úÂë¸ü¼òµ¥ 20¶àÐС£
# -*- coding: cp936 -*-
import Image
import glob, os
#ͼƬÅú´¦Àí
def timage():
for files in glob.glob('D:\\1\\*.JPG'):
filepath,filena ......
Pythonwin - Python IDE and GUI Framework for Windows.
Copyright 1994-2006 Mark Hammond
Python is Copyright (c) 2000-2008 ActiveState Software Inc.
Copyright (c) 2001-2008 Python Software Foundation.
All Rights Reserved.
Copyright (c) 2000 BeOpen.com.
All Rights Reserved.
Copyright (c) 1995-20 ......
×î½üÒòΪÑо¿Ò»¸ö¶«Î÷£¬²¢ÇÒÔںܾÃÒÔǰ¾ÍÏë°ÑpythonºÃºÃ¿´¿´¡£ÕýºÃÂú×ãÎ񵀼̮æÐÄ¡£ÎÒÿÌìÉϰà×öµÃÓÎÏ·¶¼ÊÇÓÃlua£¬Ò²ÊÇÒ»ÃźÜÇ¿´óµÄ½Å±¾ÓïÑÔ¡£¿ÉÄÜÎÒ¸üϲ»¶pythonµÄËõ½øÇø·ÖºÍÃæÏò¶ÔÏó°É¡£ ½ñÌìֻдһ¸ö¼òµ¥µÄÀý×Ó¡£Ò»¸ö¼òµ¥µÄpython½Å±¾£¬¾ÍÒ»¸öº¯Êý£¬ÓÃC/C++È¥µ÷Ó᣿ÉÄÜÕâÒ²ÊÇ×÷Ϊ³ÌÐòÀ´Ëµ×î¹ØÐĵÄÒ»¼þÊ¡£ËùÒÔÎÒµÄpytho ......
>>> a = {'1':'2'}
>>> b = {'3':'4'}
>>> a+b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'dict' and 'dict'
>>> a.update(b)
>>> a
{'1': '2', '3': '4'} ......
3. Dictionaries ×ÖµäÀàÐÍ
PythonÖУ¬×ÖµäÀàÐͲ¢²»ÊÇ˳ÐòÈÝÆ÷£¬¶øÀàËÆc++ÖеĹØÁªÈÝÆ÷(map)£¬DictionariesÖд洢µÄÊǼü/Öµ ¶Ô£¬ºÍmap²»Í¬µÄÊÇ£¬PythonµÄDictionariesÖпÉÒÔ´æÈÎÒâ¶ÔÏóÀàÐÍ¡£DictionariesÀàÐÍÒ²ÊǿɱäµÄ£¬ºÍListsÒ»Ñù£¬¿ÉÒÔÔµØÐ޸ģ¨Í¨¹ýϱêÐ޸ģ©¡£
ÏÂÃæÍ¨ ......