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

Python ιʶøÖªÐÂ

1. ´òÓ¡±äÁ¿ºÍ±äÁ¿×ÔÏÔ
>>> myString = 'Hello World!'
>>> print myString
Hello World!
>>> myString
'Hello World!'
ÒòΪ£º print Óï¾äµ÷ÓÃstr()º¯ÊýÏÔʾ¶ÔÏ󣬶ø½»»¥Ê½½âÊÍÆ÷Ôòµ÷ÓÃrepr()º¯ÊýÀ´ÏÔʾ¶ÔÏó
sys.stdout.write('hello')²»»áÔÚĩβ¼ÓÉÏ'\n'£¬¶øprint»á
2. ´òÓ¡Îļþ
handle = open('poem.txt', 'r')
for eachline in handle:
    print eachline,
handle.close()
ÊÊÓÃÓÚÎļþ´óСÊÊÖеÄÎļþ¡£¶ÔÓںܴóµÄÎļþÀ´Ëµ£¬ ÉÏÃæµÄ´úÂë»áÕ¼ÓÃÌ«¶àµÄÄڴ棬 ÕâʱÄã×îºÃÒ»´Î¶ÁÒ»ÐÐ
3. Ä£¿éÔÙÒé
Ä£¿éÊÇÒ»ÖÖ×éÖ¯ÐÎʽ£¬ Ëü½«±Ë´ËÓйØϵµÄPython ´úÂë×éÖ¯µ½Ò»¸ö¸ö¶ÀÁ¢Îļþµ±ÖС£
Ä£¿é¿ÉÒÔ°üº¬¿ÉÖ´ÐдúÂ룬 º¯ÊýºÍÀà»òÕßÕâЩ¶«Î÷µÄ×éºÏ¡£
4. ʵÓú¯Êý
dir([obj])              ÏÔʾ¶ÔÏóµÄÊôÐÔ£¬Èç¹ûûÓÐÌṩ²ÎÊý£¬ ÔòÏÔʾȫ¾Ö±äÁ¿µÄÃû×Ö
help([obj])           ÒÔÒ»ÖÖÕûÆëÃÀ¹ÛµÄÐÎʽ ÏÔʾ¶ÔÏóµÄÎĵµ×Ö·û´®£¬ Èç¹ûûÓÐÌṩÈκβÎÊý£¬ Ôò»á½øÈë½»»¥Ê½°ïÖú¡£
int(obj)                ½«Ò»¸ö¶ÔÏóת»»ÎªÕûÊý
len(obj)               ·µ»Ø¶ÔÏóµÄ³¤¶È
open(fn, mode)   ÒÔ mode('r' = ¶Á£¬ 'w'= д)·½Ê½´ò¿ªÒ»¸öÎļþÃûΪ fn µÄÎļþ
range([[start,]stop[,step]) ·µ»ØÒ»¸öÕûÊýÁÐ±í¡£ÆðʼֵΪ start, ½áÊøֵΪ stop - 1; startĬÈÏֵΪ 0£¬ stepĬÈÏֵΪ1¡£
raw_input(str)  µÈ´ýÓû§ÊäÈëÒ»¸ö×Ö·û´®£¬ ¿ÉÒÔÌṩһ¸ö¿ÉÑ¡µÄ²ÎÊý str ÓÃ×÷ÌáʾÐÅÏ¢¡£
str(obj)               ½«Ò»¸ö¶ÔÏóת»»Îª×Ö·û´®
type(obj)             ·µ»Ø¶ÔÏóµÄÀàÐÍ£¨·µ»ØÖµ±¾ÉíÊÇÒ»¸ötype ¶ÔÏ󣡣©
5. ¹Ø¼ü×Ö
and del from not while
as elif global or with
assert else if pass yield
break except import print
class exec in raise


Ïà¹ØÎĵµ£º

python±Ê¼ÇÖ®ÕýÔò±í´ïʽ

 ÕýÔò±í´ïʽ
¾ßÌåµÄ²Î¿¼ÊֲᣬÕâÀï¼ÇÏÂһЩСÎÊÌ⣺
1¡¢re¶ÔÏóµÄ·½·¨
match    Match a regular expression pattern to the beginning of a string.
search   re.search(pattern, string, flags) flags:re.I re.M re.X re.S re.L re.U
sub      Substitute oc ......

ÓÃÕ»½âÎöËãÊõ±í´ïʽ[Python°æ]

´úÂëÖвÉÓÃÁËÈý²½ÊµÏÖËãÊõ±í´ïʽµÄ½âÎö:
1. ½«ËãÊõ±í´ïʽ(×Ö·û´®)ת»»³ÉÒ»¸öÁбíparseElement·½·¨
2. ½«Áбí±íʾµÄËãÊõ±í´ïʽת»»³Éºó׺±í´ïʽchangeToSuffix
3. ¼ÆËãºó׺±í´ïʽµÄ½á¹û
ÕâÀïÎÒÊÇΪÁË·½±ã, ¾ÍдÁ˸öparseElement, ²»ÏëÄÇ·½·¨Ð´µ½ºóÃæÈ´°Ñ×Ô¼ºÈÆסÁË, ¿ÉÒÔÏëÏóÒ»¸ö´ø×ÔÔö, λ, Âß¼­, ËãÊõµÄ±í´ïʽµÄÊýÖµÌá ......

Python¿âÏê½âÖ®ÍøÂç(2)

×òÌìÊÔÁËÏÂÓÃHTMLParserÀàÀ´½âÎöÍøÒ³£¬¿É·¢ÏÖ½á¹û²¢²»ÀíÏë¡£²»¹ÜÔõô˵£¬ÏÈдϹý³Ì£¬Ï£ÍûºóÀ´ÈËÄÜÔÚ´Ë»ù´¡ÉϽâ¾öÎÒËùÓöµ½µÄÎÊÌâ¡£
дÁË2Ì×½â¾ö·½°¸£¬µ±È»Õâ2Ì×Ö»ÄܶÔÌض¨ÍøÕ¾ÓÐЧ¡£ÎÒÕâÀïÖ÷Ҫ˵Ã÷϶ÔBBCÖ÷Ò³www.bbc.co.ukºÍ¶ÔÍøÒ×www.163.comµÄ½âÎö¡£
¶ÔÓÚBBC£º
ÕâÌ×Òª¼òµ¥µÃ¶à£¬¿ÉÄÜÊǸÃÍøÒ³µÄ±àÂë±È½Ï±ê×¼°É
import ......

¿ª·¢PythonÓÃʲô¹¤¾ßºÃ£¿

    ¹¤ÓûÉÆÆäʱØÏÈÀûÆäÆ÷£¡
    ¿ª·¢PythonÓÃʲô¹¤¾ßºÃÄØ£¿Æäʵ¸ÕѧPythonµÄ»°£¬Ê¹ÓÃIDLE¾Í¹»ÁË£¬ËäÈ»µ÷ÊÔ²»ÊÇÌر𷽱㣬µ«ÊǶÔÓÚ³õѧÒѾ­¹»ÁË£¬¿ÉÒÔʹÓÃPrint½øÐмòµ¥µÄµ÷ÊÔ£¬²»½¨ÒéʹÓüÇʱ¾½øÐпª·¢£¬²»ÖªµÀµÄÈÏΪÄãºÜÅ££¬ÖªµÀµÄ……ÕâÊÇ×Ô¼º¸ø×Ô¼ºÕÒ×ïÊÜ£¬ÓÃEditplusÃ²Ë ......

pythonÖлñµÃijÔÂÓжàÉÙÌìµÄº¯Êý

  żȻÐèÒªÓõ½ÕâÑùÒ»¸öº¯Êý£¬ÔÚDelphiÖУ¬ÓÐÏֳɵĺ¯Êý¿ÉÒÔµ÷Óã¡ÔÚpythonÖУ¬ÎÒÕÒÁË°ëÌ춼»¹Ã»ÕÒµ½£¬×îºó×Ô¼ºÐ´ÁËÒ»¸öº¯ÊýÈçÏ£º
def dayOfMonth(date):
if date.month == 12:
return 31
else:
return (date.replace(month=date.month+1, day=1) - datetime.timedelta(days=1)).day
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ