美文网首页我爱编程
python基础 -- 内建工厂函数

python基础 -- 内建工厂函数

作者: fada492daf5b | 来源:发表于2018-04-13 15:44 被阅读0次

1.工厂函数

函数生成实例,一种常见的书籍模式

2.类型工厂函数

>>> a = int(9.9)
>>> a # 9
>>> b = float(8)
>>> b # 8.0
>>> c = complex(7)
>>> c # (7+0j)
>>> d = bool(None)
>>> d # False
>>> s = str(9.9)
>>> s # '9.9'
>>> l = list('python')
>>> l # ['p', 'y', 't', 'h', 'o', 'n']
>>> dt = dict(a=1)
>>> dt # {'a': 1}
>>> s=set('python')
>>> s # set(['h', 'o', 'n', 'p', 't', 'y'])
>>> s=frozenset('python')
>>> s # frozenset(['h', 'o', 'n', 'p', 't', 'y'])

查看类型

>>>a =  type(6)
>>> a # <type 'int'>

相关文章

网友评论

    本文标题:python基础 -- 内建工厂函数

    本文链接:https://www.haomeiwen.com/subject/zrhckftx.html