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

python 3.0Óëpython 2.xµÄÇø±ð

 ÕýÔÚÔĶÁ×îаæµÄ¡¶A byte of Python¡·¡£·¢ÏÖPython3.0ÔÚijЩµØ·½»¹ÊÇÓÐЩ¸Ä±äµÄ¡£×¼±¸ÂýÂýµÄÌå»á£¬ÓëÀÏ°æ±¾µÄ¡¶A byte of Python¡·×ö¶Ô±È£¬×îºóÔÙÈ¥²éÔĹٷ½ÍøÕ¾µÄÎĵµ¡£
1.
Èç¹ûÄãÏÂÔصÄÊÇ×îаæµÄPython£¬¾Í»á·¢ÏÖËùÓÐÊéÖеÄHello WorldÀý×Ó½«²»ÔÙÕýÈ·¡£
Old:
print "Hello World!" #´òÓ¡×Ö·û´®
New:
print("Hello World!")
½«×Ö·û´®·Åµ½À¨ºÅÖÐprint³öÀ´£¬ÕâÖÖд·¨¶ÔÓÚÎÒÕâÖÖѧϰJava³öÉíµÄÈËÀ´Ëµ£¬ºÜÊÇÇ×Çа¡£º£©
2.
Old:
guess = int(raw_input('Enter an integer : ')) #¶ÁÈ¡¼üÅÌÊäÈëµÄ·½·¨
New:
guess = int(input('Enter an integer : '))
·½·¨Ãû±äµÃ¸ü¼ÓÈÝÒ׼ǣ¡
3.
¼ÓÈëÁËÒ»¸öеÄnonlocal statement£¬·Ç¾Ö²¿±äÁ¿£¬ËüµÄ·¶Î§½éÓÚglobalºÍlocalÖ®¼ä£¬Ö÷ÒªÓÃÓÚº¯ÊýǶÌ×£¬Ó÷¨ÈçÏ£º
#!/usr/bin/python
# Filename: func_nonlocal.py
def func_outer():
    x = 2
    print('x is', x)
    def func_inner():
        nonlocal x
        x = 5
    func_inner()
    print('Changed local x to', x)
func_outer()
4.
VarArgs parameters£¬²»ÖªµÀÕâ¸ö·­Òë³Éʲô±È½ÏÍ×µ±£¿ÏÈ¿´Àý×Ó£º
#!/usr/bin/python
# Filename: total.py
def total(initial=5, *numbers, **keywords):
    count = initial
    for number in numbers:
        count += number
    for key in keywords:
        count += keywords[key]
    return count
print(total(10, 1, 2, 3, vegetables=50, fruits=100))
µ±ÔÚ²ÎÊýÇ°ÃæʹÓÃ*±êʶµÄʱºò£¬ËùÓеÄλÖòÎÊý£¨1£¬2£¬3£©×÷Ϊһ¸ölist´«µÝ¡£
µ±ÔÚ²ÎÊýÇ°ÃæʹÓÃ**±êʶµÄʱºò£¬ËùÓеĹؼü²ÎÊý£¨vegetables=50, fruits=100£©×÷Ϊһ¸ödictionary´«µÝ¡£
5.
¹ØÓÚPackagesµÄ»°Ì⣬ÎÒû¿´¶®¡£¡£¡£ÄÄλ´óϺ°ïæ½²½âÏ£¿
6.
ÔÚÊý¾Ý½á¹¹ÖУ¬¶àÁËÒ»ÖÖÀàÐÍ:set
SetÊÇÒ»ÖÖÎÞÐòµÄ¼òµ¥¶ÔÏóµÄ¼¯ºÏ£¬µ±ÎÒÃǹØÐÄÒ»¸ö¶ÔÏóÊÇ·ñÔÚÒ»¸ö¼¯ºÏÖдæÔÚ£¬¶ø˳ÐòºÍ³öÏֵĴÎÊýÊÇ´ÎÒªµÄʱºò£¬¿ÉÒÔʹÓÃset¡£
7.
¹ØÓÚos.sep·½·¨£¬£¨setÊÇseparator£¬·Ö¸ô·ûµ


Ïà¹ØÎĵµ£º

PythonÖÐÎÄÈ«¹¥ÂÔ

http://blog.chinaunix.net/u1/59571/showart_1901962.html
1.        ÔÚPythonÖÐʹÓÃÖÐÎÄ
ÔÚPythonÖÐÓÐÁ½ÖÖĬÈϵÄ×Ö·û´®£ºstrºÍunicode¡£ÔÚPythonÖÐÒ»¶¨Òª×¢ÒâÇø·Ö“Unicode×Ö·û´®”ºÍ“unicode¶ÔÏó”µÄÇø±ð¡£ºóÃæËùÓеēunicode×Ö·û´®”Ö¸µÄ¶¼ÊÇpyt ......

pythonÁ½¸ödictÏà¼Ó


>>> 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'} ......

ת£ºPythonµÄsort()

֮ǰѧϰµÚ¾ÅÕµÄÅÅÐòС½áµÄʱºò£¬¶Ôsort()ÅÅÐò·½·¨²»Àí½â£¬ÒòΪÀ¨ºÅÀïÃæ´øÁË×Ô¶¨ÒåµÄ±È½Ïº¯Êý¡£
ºóÀ´²éÊֲᣬ²Å·¢ÏÖsort()ÀïÃæ±¾À´¾Í´øÁËÕâÑùµÄ²ÎÊý¡£Äܹ»×Ô¶¨Òå±È½Ï·½·¨£¬È·ÊµºÜÁé»î¡£
²»½öÈç´Ë£¬ÔÚÍøÉϲ鵽һ¸ö²©¿Í£¬×÷Õß²»µ¥Í£ÁôÔÚÕâ±íÃ棬»¹²é¾¿ÁËsort()µÄÅÅÐòËã·¨£¬È·ÊµÓÐÒâ˼¡£
È«Îij­Â¼ÈçÏ£º
http://blog.done ......

pythonѧϰ

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

ÍøվģÄâµÇ½±¸Íü£¨php + python£©

 php°æ£º
<?php
$cookie_file = fopen('cookie.txt','w');//dirname(__FILE__)."/cookie_".md5(basename(__FILE__)).".txt"; // ÉèÖÃCookieÎļþ±£´æ·¾¶¼°ÎļþÃû

function vlogin($url,$data){ // Ä£ÄâµÇ¼»ñÈ¡Cookieº¯Êý
$curl = curl_init(); // Æô¶¯Ò»¸öCURL»á»°
curl_setopt($cur ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ