def rgb2hsv(r, g, b): r, g, b = r/255.0, g/255.0, b/255.0 mx = max(r, g, b) mn = min(r, g, b) m = mx-mn if mx == mn: h = 0 elif mx == r: if g >= b: h = ((g-b)/m)*60 else: h = ((g
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法setdefault() #D.get(k,d) #说明:k在D中,则返回 D[K],如果k不在D中,则返回d值 #D.get(k,d), also set D[k]=d if k not in D ''' >>> help(dict.setdefault) Help on built-in function setdefault: setdefault(...) D.set
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法fromkeys() #fromkeys() #说明:用于创建一个新字典,以序列seq中元素做字典的键,value为字典所有键对应的初始值 ''' >>> help(dict.fromkeys) Help on built-in function fromkeys: fromkeys(...) dict.fromkeys(S[,v]) -> New dict with
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法capitalize() #capitalize() #说明:将字符串的第一个字母变成大写,其他字母变小写. ''' capitalize(...) S.capitalize() -> string Return a copy of the string S with only its first character capitalized. ''' #案例 str='xiaoden
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法isupper() #http://www.runoob.com/python/att-string-isupper.html #isupper() #说明:检测字符串中所有的字母是否都为大写 ''' isupper(...) S.isupper() -> bool Return True if all cased characters in S are uppercase and
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法getattr() #getattr() #说明: ''' getattr(...) getattr(object, name[, default]) -> value default:默认值 Get a named attribute from an object; getattr(x, 'y') is equivalent to x.y. When a default argum
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法round() #http://www.cnblogs.com/hongfei/p/3858256.html #round() #说明:返回有N个小数点浮点数, ''' round(...) round(number[, ndigits]) -> floating point number Round a number to a given precision in decimal
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法id(),了解即可 #http://www.cnblogs.com/hongfei/p/3858256.html #id() #说明:查找对象的内存地址 ''' id(...) id(object) -> integer Return the identity of an object. This is guaranteed to be unique among simultaneo