python-class

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python-class相关的知识,希望对你有一定的参考价值。

 1 #!/usr/bin/env python
 2 #-*- coding:utf-8 -*-
 3 ############################
 4 #File Name: class4.py
 5 #Author: frank
 6 #Email: [email protected]
 7 #Created Time:2017-09-04 16:36:31
 8 ############################
 9 
10 #运算符重载
11 class Vector:
12     def __init__(self, a, b):
13         self.a = a
14         self.b = b
15 
16     def __str__(self):
17         return Vector (%d, %d) % (self.a, self.b)
18     
19     def __add__(self,other):
20         return Vector(self.a + other.a, self.b + other.b)
21 
22 v1 = Vector(2,10)
23 print v1
24 v2 = Vector(5,-2)
25 print v1 + v2

 

以上是关于python-class的主要内容,如果未能解决你的问题,请参考以下文章

python-class

python-class

Python-class类的相关总结

微信小程序代码片段

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js