zoukankan      html  css  js  c++  java
  • from collections import namedtuple 使用

    from collections import namedtuple
    
    
    Point = namedtuple('Point', ['x', 'y'])#本质就是等价于 class Point():
                     #                                           def __init__(self,x,y):
                     #                                                    self.x=x
                     #                                                    self.y=y
    p = Point(11, y=22) 
    print(p)

     这里面起名是有点玄学

    from collections import namedtuple
    
    
    Point = namedtuple('dsafdsf', ['x', 'y'])#本质就是等价于 class Point():
                     #                                           def __init__(self,x,y):
                     #                                                    self.x=x
                     #                                                    self.y=y
                     #得到的类就叫Point来引用即可
    p = Point(11, y=22) 
    print(p)
    View Code

     或者这种写法

    from collections import namedtuple
    
    
    Point = namedtuple('dsafdsf', 'x y')#本质就是等价于 class Point():
                     #                                           def __init__(self,x,y):
                     #                                                    self.x=x
                     #                                                    self.y=y
                     #得到的类就叫Point来引用即可
    p = Point(11, y=22) 
    print(p)
  • 相关阅读:
    phpdocumentor生成代码注释文档(linux)
    phpstorm扩展
    es教程
    康威定律
    k8s
    tidb调研
    netty 在线教程
    McQueenRPC源码阅读
    DIY一些基于netty的开源框架
    性能测试
  • 原文地址:https://www.cnblogs.com/zhangbo2008/p/9245146.html
Copyright © 2011-2022 走看看