isalpha()
関数が、str
タイプの方法ではありません。あなたがする必要がある場合は、未結合の方法として、それを抽出し、機能としてそれに名前を付けることができます。
>>> "hello".isalpha()
True
>>> "31337".isalpha()
False
>>> isalpha = str.isalpha
>>> isalpha("hello")
True
>>> isalpha("31337")
False
機能インポートされたモジュールで、そのモジュールのメンバーです。メインの名前空間に関数を引くために、from
の文を使用します。
>>> import math
>>> math.sin(3.3)
-0.1577456941432482
>>> from math import cos
>>> cos(3.3)
-0.9874797699088649
を今、なぜPythonは、このように動作しますか? math
モジュールとlogging
モジュールの両方がlog()
と呼ばれる機能を持っていますが、彼らは非常に異なることを行います。すべてのインポートされたシンボルは、メインの名前空間への道をまっすぐに行きました場合from math import *
は、プログラムは両方のモジュールのlog()
機能を使用することはできないだろうというとき
>>> import math, logging
>>> help(math.log)
log(...)
log(x[, base])
Return the logarithm of x to the given base.
If the base not specified, returns the natural logarithm (base e) of x.
>>> help(logging.log)
log(level, msg, *args, **kwargs)
Log 'msg % args' with the integer severity 'level' on the root logger. If
the logger has no handlers, call basicConfig() to add a console handler
with a pre-defined format.
は、彼らはありません。
'isalpha'は関数ではありません。これはメソッドです: 'x.isalpha()'。 – Bakuriu