关于python类和实例的一些尝试
来源:互联网 发布:大学的意义知乎 编辑:程序博客网 时间:2024/04/30 03:19
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32Type "copyright", "credits" or "license()" for more information.>>> a=5>>> b=5>>> deTraceback (most recent call last): File "<pyshell#2>", line 1, in <module> deNameError: name 'de' is not defined>>> def x(a,b): return a,b>>> x(a,b)(5, 5)>>> type(x(a,b))<class 'tuple'>>>> def y(a,b): return [a,b]>>> y(a,b)[5, 5]>>> x(a,b)[0]5>>> class student(object): def sum(self): a=5 b=6 return a+b>>> student.sum<function student.sum at 0x0000025F1939A9D8>>>> class student(object): def __init__(self): self.a=5 self.b=6 def MySum(self): return self.a+self.b>>> c=student.MySum>>> c<function student.MySum at 0x0000025F1939AAE8>>>> class student(object): def MySum(self,a,b): return a+b>>> c=student.MySum(5,6)Traceback (most recent call last): File "<pyshell#31>", line 1, in <module> c=student.MySum(5,6)TypeError: MySum() missing 1 required positional argument: 'b'>>> class student(object): def __init__(self): self.mySum=0 def MySum(self,a,b): self.mySum=a+b return self.mySum>>> c=student.MySum(5,6)Traceback (most recent call last): File "<pyshell#35>", line 1, in <module> c=student.MySum(5,6)TypeError: MySum() missing 1 required positional argument: 'b'>>> c=student()>>> c.MySum(5,6)11>>> class student(object): def __init__(self,a,b): self.mySum=a+b return self.mySum>>> student(5,6)Traceback (most recent call last): File "<pyshell#41>", line 1, in <module> student(5,6)TypeError: __init__() should return None, not 'int'>>> class student(object): def __init__(self,a,b): self.mySum=a+b>>> student(5,6).mySum11>>>
0 0
- 关于python类和实例的一些尝试
- 关于DLL的一些尝试
- 一些没有尝试的android 经典实例
- 关于视频录制的一些尝试
- 关于Python中None的一点尝试
- 关于Python中dic的一点尝试
- 关于typedef和指针函数的用法的一些尝试,依然有些不求甚解-C语言
- 关于vim究竟强大在哪里的一些思考和尝试
- Python--关于for和if的一些
- 关于python的一些想法和疑惑
- 关于"尝试实例化的函数不是构造函数"
- 关于Shell.Application对象的一些简单尝试
- numpy基础——关于 ndarray 的一些尝试
- 关于静态方法和实例方法的一些误区。
- 关于async和await的一些误区实例详解
- 关于Python操作txt文件的一点尝试
- Python:尝试写一个简单的类
- Python关于socket的一个小型服务器和客户机实例
- 递归生成格雷码
- 凸优化笔记(一):仿射集,凸集与锥
- POJ
- 设计模式之建造者模式(Builder Pattern)
- 二叉树深度优先遍历
- 关于python类和实例的一些尝试
- 基于C++的任意格式图片显示及RGB读取
- OpenGL——光照系统
- Base64简介
- GYM 100182 B.Euclid(计算几何)
- 401. Binary Watch
- Problem--82A--Codeforces--Double Cola
- Web系统与技术--使用Markdown
- codeforces 554c[补]