例一:for循环 for i in range(1,100): if i==23: print "great,%s you got your lucky number:" %(i) break else: print 'the number is :',i 运行:windows下 切换到目录下 Python xunhuan.py linux 下 cd到目录下 Python xunhuan.py 例二:阶乘的例子 n=int(input('Enter an integer &…
例一:匹配长度为1-15的域名 #-*-encoding:utf--*- import re regex=re.compile('^www[.][a-z]{1,15}[.](com|org)') m1=re.match(regex, 'www.baidu.com') #m2=re.match(regex, 'abcdefghig') if m1 is not None: print 'true1' #if m2 is not None: # print 'true2' 例二:匹配010 022之…
例1.构造函数 #-*-coding:utf--*- import sys class Student: def __init__(self,name,age): self.__name=name self.__age=age def getName(self): format="my name is %s my age is %d"%(self.__name,self.__age) print format def __del__(self): print "del&quo…
From:http://learnpythonthehardway.org/book/ex37.html 1. with X as Y: pass 1.1 yield 2. exec 2.1 namespace 3. lambda 3.1 map 3.2 map and reduce 4. raise KEYWORD DESCRIPTION EXAMPLE and Logical and. True and False == False as (1) Part of the with-as st…