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

python ¼¯ºÏÔËËã

¼¯ºÏÀàÐͲÙ×÷·û£¨ËùÓеļ¯ºÏÀàÐÍ£©
ÁªºÏ( | )
ÁªºÏ(union)²Ù×÷ºÍ¼¯ºÏµÄOR(ÓֳƿɼæÎöÈ¡(inclusive
disjunction))ÆäʵÊǵȼ۵ģ¬Á½¸ö¼¯
ºÏµÄÁªºÏÊÇÒ»¸öм¯ºÏ£¬¸Ã¼¯ºÏÖеÄÿ¸öÔªËض¼ÖÁÉÙÊÇÆäÖÐÒ»¸ö¼¯ºÏµÄ³ÉÔ±£¬¼´£¬ÊôÓÚÁ½¸ö¼¯ºÏÆä
ÖÐ
Ö®Ò»µÄ³ÉÔ±¡£ÁªºÏ·ûºÅÓÐÒ»¸öµÈ¼ÛµÄ·½·¨£¬union().
Edit By Vheavens
Edit By Vheavens
>>>
s | t
set(['c', 'b', 'e', 'h', 'k', 'o', 'p', 's'])
½»¼¯( & )
Äã
¿ÉÒ԰ѽ»¼¯²Ù×÷±È×ö¼¯ºÏµÄAND(»òºÏÈ¡)²Ù×÷¡£Á½¸ö¼¯ºÏµÄ½»¼¯ÊÇÒ»¸öм¯ºÏ£¬¸Ã¼¯ºÏÖеÄÿ
¸öÔªËØͬʱÊÇÁ½¸ö¼¯ºÏÖеijÉÔ±£¬¼´£¬ÊôÓÚÁ½¸ö¼¯ºÏµÄ³É
Ô±¡£½»¼¯·ûºÅÓÐÒ»¸öµÈ¼ÛµÄ·½·¨£¬
intersection().
>>> s & t
set(['h',
's', 'o', 'p']
²î²¹/Ïà¶Ô²¹¼¯( � )
Á½¸ö¼¯ºÏ(s
ºÍt)µÄ²î²¹»òÏà¶Ô²¹¼¯ÊÇÖ¸Ò»¸ö¼¯ºÏC£¬¸Ã¼¯ºÏÖеÄÔªËØ£¬Ö»ÊôÓÚ¼¯ºÏs£¬¶ø²»Êô
ÓÚ¼¯ºÏt¡£²î·ûºÅÓÐÒ»¸öµÈ¼ÛµÄ·½·¨£¬difference().
>>>
s - t
set(['c', 'e'])
¶Ô³Æ²î·Ö( ^ )
ºÍÆäËûµÄ²¼¶û¼¯ºÏ²Ù×÷ÏàËÆ£¬¶Ô³Æ²î·ÖÊǼ¯ºÏµÄXOR(ÓÖ³Æ"Òì
»ò" (exclusive disjunction)).
Á½¸ö¼¯ºÏ(s
ºÍt)µÄ¶Ô³Æ²î·ÖÊÇÖ¸ÁíÍâÒ»¸ö¼¯ºÏC,¸Ã¼¯ºÏÖеÄÔªËØ£¬Ö»ÄÜÊÇÊôÓÚ¼¯ºÏs »òÕß¼¯ºÏt
µÄ³ÉÔ±£¬²»ÄÜͬʱÊôÓÚÁ½¸ö¼¯ºÏ¡£¶Ô³Æ²î·ÖÓÐÒ»¸öµÈ¼ÛµÄ·½
·¨£¬symmetric_difference().
>>> s ^ t
set(['k', 'b', 'e',
'c'])
»ìºÏ¼¯ºÏÀàÐͲÙ×÷
ÉÏÃæµÄʾÀýÖУ¬×ó±ßµÄs Êǿɱ伯ºÏ£¬¶øÓұߵÄt ÊÇÒ»¸ö²»¿É±ä¼¯ºÏ. ×¢ÒâÉÏÃæʹÓü¯ºÏ²Ù×÷
ÔËËã·û
Ëù²úÉúµÄÈÔÈ»Êǿɱ伯ºÏ,µ«ÊÇÈç¹û×óÓÒ²Ù×÷ÊýµÄ˳Ðò·´¹ýÀ´£¬½á¹û¾Í²»Ò»ÑùÁË:
>>> t | s
frozenset(['c',
'b', 'e', 'h', 'k', 'o', 'p', 's'])
>>> t ^ s
frozenset(['c',
'b', 'e', 'k'])
>>> t - s frozenset(['k', 'b'])
Èç¹û×óÓÒÁ½¸ö²Ù×÷
ÊýµÄÀàÐÍÏàͬ£¬¼È¶¼Êǿɱ伯ºÏ»ò²»¿É±ä¼¯ºÏ, ÔòËù²úÉúµÄ½á¹ûÀàÐÍÊÇÏàͬ
µÄ£¬µ«Èç¹û×óÓÒÁ½¸ö²Ù×÷ÊýµÄÀàÐͲ»Ïàͬ(×ó²Ù×÷ÊýÊÇset£¬ÓÒ²Ù×÷ÊýÊÇ
frozenset£¬»òÏà·´Çé¿ö)£¬
Edit By Vheavens
Edit By Vheavens
ÔòËù²úÉúµÄ½á¹ûÀàÐÍÓë×ó
²Ù×÷ÊýµÄÀàÐÍÏàͬ£¬ÉÏÀýÖпÉÒÔÖ¤Ã÷ÕâÒ»µã¡£»¹Òª×¢Ò⣬¼ÓºÅ²»ÊǼ¯ºÏÀà
Ð͵ÄÔËËã·û:
>>> v = s + t
Traceback
(most recent call last):
File "<stdin>", line 1, in ?
TypeError:
unsupported operand type(s) for +: 'set' and 'set


Ïà¹ØÎĵµ£º

Amusing Python 2: range/xrange

ÕâÁ½¸ö»ù±¾É϶¼ÊÇÔÚÑ­»·µÄʱºòÓá£
Python
´úÂë < type="application/x-shockwave-flash" width="14" height="15" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=for%20i% ......

Python Áбí(list)²Ù×÷

´´½¨Áбí
sample_list = ['a',1,('a','b')]
Python Áбí²Ù×÷
sample_list = ['a','b',0,1,3]
µÃµ½ÁбíÖеÄijһ¸öÖµ
value_start = sample_list[0]
end_value =
sample_list[-1]
ɾ³ýÁбíµÄµÚÒ»¸öÖµ
del sample_list[0]
ÔÚÁбíÖвåÈëÒ»¸öÖµ
sample_list[0:0] = ['sample value']
µÃµ½ÁбíµÄ³¤¶È
list_length = ......

Python±ê×¼¿â randomÄ£¿é


Python±ê×¼¿â-randomÄ£¿é
random Ä£¿é°üº¬Ðí¶àËæ»úÊýÉú³ÉÆ÷. »ù±¾Ëæ»úÊýÉú³ÉÆ÷(»ùÓÚ Wichmann ºÍ Hill , 1982 µÄÊýѧÔËËãÀíÂÛ) ¿ÉÒÔͨ¹ýºÜ¶à·½·¨·ÃÎÊ, Èç Example 2-29 Ëùʾ. 2.17.0.1. Example 2-29. ʹÓà random Ä£¿é»ñµÃËæ»úÊý×Ö File: random-example-1.py import random for i i
¡¡¡¡
random Ä£¿é°üº¬Ðí¶àËæ»úÊýÉ ......

python ³õÌåÑé

windowsÏÂ
1 ÏÂÔØpython°²×°°ü£¬ һ·ÏÂÈ¥°²×°
2 ÏÂÔØmysqldb°²×°
3 ÏÂÔØdjangoÎļþ£¬ dyango-admin.py install Íê³É
£­£­£­£­£­Èç¹ûÆô¶¯ºó±¨´íimport error: dll load failed. ÐèÒªÔÚsite-packageÏÂÔö¼Ódll: libguide40.dll  libmmd.dll  libmySQL.dll
´´½¨Ó¦ÓÃºó£¬ manage.py µÄprogram argumentÖÐÓ¦ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ