python内置函数 build_in_functions

上一篇 / 下一篇  2017-08-29 11:20:40 / 个人分类:python

参考地址:
#-*- coding:utf-8 -*-
import sys
import time

#definition de
# message = u'Call me at 415-555-4242 tomorrow . 415-555-9999 is my office'
# for i in range(len(message)):
# chunk = message[i:i+12]
# if isPhoneNumber(chunk):
# print ('Phone number found:'+chunk)
# print('Done')
#take the remainder
# print divmod(2, 5)

#catch user's input
# a=input('input:')
# b=raw_input('input2:')
# print a,b

#static method
# class C(object):
# #staticmethod not need instantiation
# #@staticmethod
# def f(agrgs):
# print ('static method')

#staticmethod can immediate call
# C.f('a')

#not staticmethod need instantiation
# name=C()
# name.f()

#all function
# def all(iterable):
# #iterable is a tuple or list
# for element in iterable:
# if not element:
# print 'false'
# return False
# print 'true'
# return True
# all(['a',False])
# all(['a',''])
# all(['a',0])
# all(['a'])

#enumerater()
# seasons=['zhuhuan','zhuhuanya','huanhuan']
# print list(enumerate(seasons))
# print list(enumerate(seasons,start=1))

#
# def enumerater(sequence,start=0):
# n=start
# for elem in sequence:
# yield n,elem
# n+=1
# print list(enumerater(['zhuhuan','zhuhuanya','huanhuan'],start=0))

# print int(' 123')

# print chr(57)
# print chr(0x30)

# print ord(u'\u0031')#unicode转换为10进制
# print ord(u'\u2020')

# a=str(' 12')
# b=int(a)
# print a,b

def any(iterable):
for element in iterable:
if element:
print 'true'
return True
print 'false'
return False
# any([''])


# x=123
# print eval('3+x')

# y=1
# # print isinstance(y,str)
# print isinstance(1,(str,int,list))

#the different of isinstance and type
class A:
pass

class B(A):
pass
# print isinstance(A(),A)
# print type(A()) == A
# print isinstance(B(),A)
# print type(B())==A
# print issubclass(A,B) #返回false
# print issubclass(B,A) #返回true,类B是参数类A的子集 类A必须先于类B存在

# print pow(9,3,5) #计算9的3次方后的值除以5取余数(取模)

# print sum([1,2,3],9) #求和,相对于 1+2+3+9
# # print sum(1,3) #报错:不是iterable
# # print sum(['a','b']) #报错:迭代值不能为str类型
# print sum([1.22,2.33]) #求和

# print isinstance('hello',basestring) #判断参数是否为str 或者Unicode类型 ,返回true
# print isinstance(1,basestring) #返回false
# print isinstance(u'\u2020',basestring) #参数为Uniexecfilecode类型,返回true

# #此处的if 注意缩进
# if __name__== '__main__':
# print sys.argv
# print 'execfile'
# sys.argv = 'appcfg.py update sdblog'.split();
# print sys.argv
# #execfile打开文件
# execfile('main.py')

#super 调用父类并返回该父类实例的方法
class FooParent(object):
def __init__(self):
self.parent='I \'m the parent' #创建parent属性
print 'Parent'
def bar(self,message):
print message,'from Parent'
class FooChild(FooParent):
def __init__(self):
super(FooChild,self).__init__()
print 'Child'
def bar(self,message):
super(FooChild,self).bar(message)
print 'Child bar function'
print self.parent
# if __name__=='__main__':
# fooChild=FooChild()
# print '\n'
# fooChild.bar('HelloWorld')


# print bin(12345) #转换int类型为二进制
# # print bin('a') #报错,不能传递str类型,只能传递int类型 参数
# # print bin(1.22) #报错,不能传递float类型,只能传递int类型 参数

# f=file('test.txt')
# print f
# print f.read()

# with open('test.txt') as fp:
# for line in iter(fp.readline,''): #如果第一个参数不是可迭代的参数,则必须传递第二个参数
# print line
#
# mylist=[1,2,3]
# for i in iter(mylist):
# print i

class C(object):
@classmethod
def __call__(self):
return 0
def __init__(self):
self._x='la la la'
def getx(self):
return self._x
def setx(self,value):
self._x=value
def delx(self):
del self._x
def __dir__(self):
self._x='aaa'
x=property(getx,setx,delx,"i'm the 'x' property")
y=property(getx)
u = property(getx,setx)
# name=C()
# print dir(C) #返回对象的属性、方法和列表

# myProperty=name.x
# print myProperty
# y=name.y
# print y
# u=name.u
# print u

# print vars(time) #以字典形式打印出time模块对象
# print vars(C) #类
# c=C()
# print vars(c) #实例

# print C.__call__() #@classmethod 修饰符修饰的函数不需要实例化
# print C().__call__() #无@classmethod修饰符函数的调用

# myAttribute=name.getx()
# print myAttribute


# myList=[1,22,44]
# print tuple(myList)
# print tuple('abc')

# class bool():
# de

TAG:

 

评分:0

我来说两句

Open Toolbar