相关疑难解决方法(0)

在Python中,避免对__init__参数和实例变量使用相同名称的最佳方法是什么?

什么是在init函数中初始化实例变量的最佳方法.两次使用相同的名字是不好的风格?

class Complex:
     def __init__(self, real, imag):
         self.real = real
         self.imag = imag
Run Code Online (Sandbox Code Playgroud)

对我来说,提出像这样的任意替代名称看起来很草率:

class Complex:
     def __init__(self, realpart, imagpart):
         self.r = realpart
         self.i = imagpart
Run Code Online (Sandbox Code Playgroud)

我不认为这在PEP 8风格指南中得到了解决.它只是说实例变量和方法名称应该是小写的,下划线分隔单词.

python coding-style naming-conventions

2
推荐指数
1
解决办法
155
查看次数

标签 统计

coding-style ×1

naming-conventions ×1

python ×1