# staticmethod

静态方法（@staticmethod）

* 不能访问类属性和实例属性
* 改静态方法函数里不传入self 或 cls

```python
class cal:
    cal_name = '计算器'

    def __init__(self, x, y):
        self.x = x
        self.y = y

    @staticmethod  # 静态方法 类或实例均可调用
    def cal_test(a, b, c):  # 改静态方法函数里不传入self 或 cls
        print(a, b, c)
        # print(self.x) #压根没self，所以自然用不了
        # print(cal_name) #隐性self也用不了


c1 = cal(10, 11)

cal.cal_test(1, 2, 3)#直接不创建对象实例能用
c1.cal_test(1, 2, 3)#创建了也能用，不过不属于这个实例，这个是大家公用的
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/python/zhuang-shi-qi/staticmethod.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
