jay*_*qui 15 python naming-conventions
我是Rubyist学习Python,我想知道Python中是否有一个约定如下.
在Ruby中,返回布尔值的方法应该始终以a结尾?.例如,
def palindrome?(string)
# some code that tests whether string is a palindrome
end
Run Code Online (Sandbox Code Playgroud)
我能找到的唯一现有的SO问题并没有提供明确的答案.
我同意@CarolChen关于转向PEP8(Python样式指南)的原则以获得指导.然而,我会建议"视需要提高可读性"是旁观者的眼睛.例如,这些函数中的每一个都在Python中用作str对象的函数或内置函数.这些都是Python生态系统中的基础,并且是一个使用样式的好例子,专注于返回布尔状态并具有易于读取的函数名称.
海峡.方法
isalnum()
isalpha()
isdecimal()
isdigit()
isidentifier()
islower()
isnumeric()
isprintable()
isspace()
istitle()
isupper()
Run Code Online (Sandbox Code Playgroud)
内置功能:
isinstance()
issubclass()
Run Code Online (Sandbox Code Playgroud)
你可以这样定义它
def is_palindrome(variable):
# your logic\
# return True / False
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6750 次 |
| 最近记录: |