pythonÀàÐÍת»»¡¢ÊýÖµ²Ù×÷
2008-12-21
pythonÀàÐÍת»»¡¢ÊýÖµ²Ù×÷
¹Ø¼ü×Ö: pythonÀàÐÍת»»¡¢ÊýÖµ²Ù×÷
pythonÀàÐÍת»»
Java´úÂë
º¯Êý ÃèÊö
int(x [,base ]) ½«xת»»ÎªÒ»¸öÕûÊý
long(x [,base ]) ½«xת»»ÎªÒ»¸ö³¤ÕûÊý
float(x ) ½«xת»»µ½Ò»¸ö¸¡µãÊý
complex(real [,imag ]) ´´½¨Ò»¸ö¸´Êý
str(x ) ½«¶ÔÏó x ת»»Îª×Ö·û´®
repr(x ) ½«¶ÔÏó x ת»»Îª±í´ïʽ×Ö·û´®
eval(str ) ÓÃÀ´¼ÆËãÔÚ×Ö·û´®ÖеÄÓÐЧPython±í´ïʽ,²¢·µ»ØÒ»¸ö¶ÔÏó
tuple(s ) ½«ÐòÁÐ s ת»»ÎªÒ»¸öÔª×é
list(s ) ½«ÐòÁÐ s ת»»ÎªÒ»¸öÁбí
chr(x ) ½«Ò»¸öÕûÊýת»»ÎªÒ»¸ö×Ö·û
unichr(x ) ½«Ò»¸öÕûÊýת»»ÎªUnicode×Ö·û
ord(x ) ½«Ò»¸ö×Ö·ûת»»ÎªËüµÄÕûÊýÖµ
hex(x ) &nbs
Ïà¹ØÎĵµ£º
pythonµÄC¡¢c++À©Õ¹
http://blog.chinaunix.net/u3/110228/showart_2148725.html
pythonµÄÇ¿´ó²»½ö±íÏÖÔÚÆ书ÄÜÉÏ£¬¶øÇÒ»¹±íÏÖÔÚÆäÀ©Õ¹ÄÜÁ¦ÉÏ¡£
ʹÓÃC/C++ºÜÈÝÒ×±àдpythonµÄÄ£¿é£¬À©Õ¹pythonµÄ¹¦ÄÜ¡£
ͬʱ½«ÐÔÄÜÒªÇó±È½Ï¸ßµÄ´úÂëʹÓÃC/C++±àд£¬ÄܸüºÃµÄÃÖ²¹
½Å±¾ÓïÑÔÖ´ÐÐËÙ¶ÈÂýµÄȱÏÝ¡£
1. pythonµÄCÓïÑÔÀ©Õ¹
1.1 ......
ÏеÄÎÞÁľͿ´ÁËÒ»µã¹ØÓÚpythonµÄ»ù´¡ÖªÊ¶£¬µ±Ê±Ò²²»ÖªµÀpythonºÍperlÖ®¼äÕùÂÛµÄÕâôµÄ¼¤ÁÒ£¨Ö÷ÒªÊǵ±Ê±²»ÖªµÀperlÕâ¸öÓïÑÔµÄÐÔÖÊ),ËùÒÔÖ±½Ó¾Í¿´ÁËpython£¬ÏÂÃæÊÇÎҵĵÚÒ»¸öÓÃpythonдµÄС³ÌÐòÔ´Â룬ϣÍûÅóÓÑÃǶà¶àÖ¸½Ì£¬ÓÐʲôÎÊÌâ´ó¼Ò¾¡¹ÜÖ¸Õý£¬ÔÚ´ËÏÈлл´ó¼ÒÁË¡£
[code]
#!/usr/bin/python
import sys, os, re
impor ......
python µÄÄÚǶtimeÄ£°å·Ò뼰˵Ã÷
Ò»¡¢¼ò½é
timeÄ£¿éÌṩ¸÷ÖÖ²Ù×÷ʱ¼äµÄº¯Êý
˵Ã÷£ºÒ»°ãÓÐÁ½ÖÖ±íʾʱ¼äµÄ·½Ê½:
µÚÒ»ÖÖÊÇʱ¼ä´ÁµÄ·½Ê½(Ïà¶ÔÓÚ1970.1.1 00:00:00ÒÔÃë¼ÆËãµÄÆ«ÒÆÁ¿),ʱ¼ä´ÁÊÇΩһµÄ
µÚ¶þÖÖÒÔÊý×éµÄÐÎʽ±íʾ¼´(struct_time),¹²ÓоŸöÔªËØ£¬·Ö±ð±íʾ£¬Í¬Ò»¸öʱ¼ä´ÁµÄstruct_time»áÒòΪʱÇø²»Í¬¶ø²»Í¬
year ......
Öð²½Ñݽø
f=open('/etc/motd','r')
longest=0
while True:
lineLen=len(f.readline().strip())
if not lineLen: break
if lineLen > longest:
longest=lineLen
f.close()
return longest
ÎÊÌâ£ºÒ»Ö±Õ¼Ó ......
±³¾°
ÏîÄ¿µÄ
×Ô¶¯»¯²âÊÔÖÐÒѾʹÓÃÁË»ùÓÚPython
½Å±¾µÄ¿ò¼Ü£¬×Ô¶¯»¯¹ý³ÌÖÐ×î¹Ø¼üµÄÎÊÌâ¾ÍÊÇÈçºÎʵÏÖ׮ģ¿é¡£ÔËÓÃ
Python
Ç¿´óµÄ¹¦ÄÜ£¬ÊµÏÖÈκÎ׮ģ¿é¶¼ÊÇ¿ÉÄܵģ¬µ«ÊÇÊÇ·ñ±ØÐëÍêȫʹÓÃ
Python
ʵÏÖÄ£¿éÂß¼£¬³É±¾ÊÇÒ»¸ö¾ö¶¨ÐÔÒòËØ¡£ÔÚ׮ģ¿éÂß¼¼òµ¥µÄÇé¿öÏ£¬Ê¹ÓÃ
Python
Ä£ÄâÄ£¿éÂß¼²»µ«Ê¹×Ô¶¯»¯²âÊԵĽṹÇå ......