Pythond类在函数中的编程方法

开发 后端
Pythond类有很广泛的应用范围,在很长时间的应用中有不少的问题需要我们进行学习。下面我们就详细的看看相关的技术知识。

Pythond类如何进行相关的应用呢?这个问题需要我们不断的学习。下面我们就来介绍下Pythond类的函数编程。只有不断的学习才能更好的使用。Python属于函数是编程。

Python代码

  1. '''''   
  2. Created on 2009-11-18   
  3. @author: Administrator   
  4. '''   
  5. class MyClass(object):   
  6. '''''   
  7. classdocs   
  8. '''   
  9. cl = [1,2,"5"]   
  10. def __init__(selfparams):   
  11. '''''   
  12. Constructor   
  13. '''   
  14. print "Constructor,..."   
  15. def te(self):   
  16. print "a"   
  17. '''  
  18. Created on 2009-11-18  
  19. @author: Administrator  
  20. '''  
  21. class MyClass(object):  
  22. '''  
  23. classdocs  
  24. '''  
  25. cl = [1,2,"5"]  
  26. def __init__(selfparams):  
  27. '''  
  28. Constructor  
  29. '''  
  30. print "Constructor,..."  
  31. def te(self):  
  32. print "a" 

Python代码

  1. import Class1 '''''导入Class1.py文件'''   
  2. x = Class1.MyClass() '''''生成MyClass实例'''   
  3. x.te()   
  4. print x.cl   
  5. import moa ''''''导入另外一个模块'''   
  6. print moa.__file__   
  7. print moa.__name__   
  8. '''''try catch,捕捉异常'''   
  9. try:   
  10. print "---------------"+moa.aaa(1)   
  11. except:   
  12. print "Error"   
  13. finally:   
  14. print "finally"   
  15. print moa.aaa(1)   
  16. m = moa.M()   
  17. import Class1 '''导入Class1.py文件'''  
  18. x = Class1.MyClass() '''生成MyClass实例'''  
  19. x.te()  
  20. print x.cl  
  21. import moa ''''导入另外一个模块'''  
  22. print moa.__file__  
  23. print moa.__name__  
  24. '''try catch,捕捉异常'''  
  25. try:  
  26. print "---------------"+moa.aaa(1)  
  27. except:  
  28. print "Error"  
  29. finally:  
  30. print "finally"  
  31. print moa.aaa(1) 

 

在 Python 中的 import 就像 Perl 中的 require 。import 一个 Python 模块后,您就可以使用 module .function 来访问它的函数;require 一个 Perl 模块后,您就可以使用 module ::function 来访问它的函数。

【编辑推荐】

  1. Python主线程如何进行相关应用
  2. Python script代码在C++中的使用方法
  3. Python next函数实际操作教程
  4. Python正则表达式的几种匹配方法
  5. Python语言使用特点介绍
责任编辑:张浩 来源: 博客园
相关推荐

2017-10-17 16:23:58

函数式编程ReduxReact

2010-03-10 11:11:16

Python编程

2009-06-29 17:57:30

ApplicationJSP

2009-08-05 15:17:02

NTILE函数

2021-06-15 07:33:13

Java函数式编程

2010-06-22 13:32:26

函数式编程JavaScript

2009-12-01 14:46:16

PHP mb_subs

2010-09-14 17:27:27

SQL函数

2010-08-03 08:54:07

JDK 7Lambda表达式函数式编程

2021-05-07 09:31:10

三角函数指数函数取整函数

2019-01-17 10:25:56

Python编程语言程序员

2020-08-20 08:23:52

VueDOM运算符

2010-09-10 16:02:13

SQLCHARINDEX函数

2009-07-21 17:21:57

Scala定义函数

2014-04-23 13:30:23

类簇iOS开发

2009-01-16 08:52:26

面向对象OOP编程

2010-07-20 09:13:55

Perl面向对象编程

2023-11-05 12:20:10

匿名函数Golang

2020-09-23 16:07:52

JavaScript函数柯里化

2010-03-15 10:24:20

Python函数变量
点赞
收藏

51CTO技术栈公众号