痴心VS绝对 发表于 2017-4-21 10:36:47

Python学习第一天-Python中的类

  Dive Into Python
 

http://www.tsnc.edu.cn/default/tsnc_wgrj/doc/pythonhtml/html/toc/index.html
  安装Python 2.6
  开发工具使用Aptana+ Python插件(Aptana自带的插件)
  类中的方法一般都有一个self参数,这个参数在调用的是很不需要传递,系统会默认传递自身过去。
  Python属于函数是编程。
  Pythond中的类
  Class1.py

'''
Created on 2009-11-18
@author: Administrator
'''
class MyClass(object):
'''
classdocs
'''
cl =
def __init__(selfparams):
'''
Constructor
'''
print "Constructor,..."
def te(self):
print "a"

 
import Class1 '''导入Class1.py文件'''
x = Class1.MyClass()'''生成MyClass实例'''
x.te()
print x.cl
import moa ''''导入另外一个模块'''
print moa.__file__
print moa.__name__
'''try catch,捕捉异常'''
try:
print "---------------"+moa.aaa(1)
except:
print "Error"
finally:
print "finally"
print moa.aaa(1)
m = moa.M()

  
 
在 
Python
 
中的 
import
 
就像 
Perl
 
中的 
require
。import
 
一个 
Python
 
模块后,您就可以使用 
module
.function

 
来访问它的函数;require
 
一个 
Perl
 
模块后,您就可以使用 
module
::function

 
来访问它的函数。
页: [1]
查看完整版本: Python学习第一天-Python中的类