# -*- coding: utf-8 -*-
#print u'你好utf8'
# #测试python中的一些内置函数
# #abs 绝对值函数,在hello1.py中手动写了几行绝对值程序,但是没有输入限制,abs只允许输入一个正数或负数
# print abs(100)
# print abs(-200)
# #abs(a) 将会报错
# # cmp(x,y) 比较函数,如果x<y 返回1
# x = raw_input('plz input x: ')
# y = raw_input('plz input y: ')
# if cmp(x,y) == -1:
# print u'x > y ,返回值为-1'
# elif cmp(x,y) == 0:
# print u'x = y, 返回值为0'
# else:
# print u'x < y, 返回值为1'
# func1 = abs
# func2 = cmp
# print func1(-10)
# print func2(2,3)
# # 还有一些类型转换函数
# print int('123456') +1
# print bool(1)
# # all(iterable)->bool
# print all([2,'',1])
# print all([]) #if the iterable is empty,return true
# print #输出新行,在3.x版本中去除了print语句,而被print()函数替代
# print any([0,1,''])
# print any([]) #if the iterable is empty,return false
# #basestring string和unicode的超类,在3.x版本中已经去除,不能被调用或实例化
# #使用2to3工具将所有的basestring替换为str
# print isinstance('hello, world',str)
# print isinstance('hello, world',basestring)
# print isinstance(u'你好',unicode)
# print isinstance(u'你好',basestring)
# # 定义函数 define function with def
# def isAstring(anobj):
# return isinstance(anobj,basestring)
# print isAstring(u'你好')
# # bin函数,将x转换为二进制字 符 串。若x不为int型,则x中必须包含__index()__,并且返回值为integer
# print bin(511) #使用0b来表示字符串为一个二进制字符串
# #非int型
# class myType:
# def __index__(self):
# return 510
# myvar = myType()
# print bin(myvar)
# bytearray,返回一个byte数组
# a = bytearray(3)
# print a
# print a[0]
# print len(a)
# b = bytearray('abcdef')
# print b
# print b[0]
# print len(b)
# c = bytearray([1,2,254]) #if its an iterable,then the element must between 0-255
# for sth in c:
# print sth
# print c[-1]
# print len(c)
# callable,判断元素是否可调用
print callable(basestring)
print callable(callable)
class callClassA:
def method(self):
return 0
print callable(callClassA) #true
a = callClassA()
print callable(a) #false
class callClassB:
def __call__(self):
pass #使用pass占位,解释器会跳过这一行,否则会报错
print callable(callClassB) #true
b = callClassB();
print callable(b) #true