初学Python

最近初学python,做点小笔记:

class Calculator:
    def add(self, a, b):
        return a + b

    def subtract(self, a, b):
        return a - b

    def multiply(self, a, b):
        return a * b

    def divide(self, a, b):
        return a / b


calculator = Calculator()
result = calculator.divide(2, 4)
print result

上面是Python的一个计算器类,可以做加减乘除操作。

Python的特点:

1、利用缩进,而不是括号{}

2、是脚本语言,面向对象,也有垃圾回收,也有class,被解释器执行

3、模块很多,可以安装相应的模块,实现相应的功能

原文地址:https://www.cnblogs.com/shuada/p/6962329.html