license
前回にあった_Printerシリーズですね。
Type license() to see the full license text
printするとこのメッセージが出てきて、license()とすると
長いライセンステキストが出てきます。
help
これも_Printerと思いきや_Helperです。
なんとオブジェクトを引数に渡すとそのオブジェクトのヘルプが表示されます。
引数に何も渡さないと対話型ヘルプになります。
from typing import Literal
help(Literal)
こういうコードを書くと、
Help on _LiteralSpecialForm in module typing:
Literal = typing.Literal
Special typing form to define literal types (a.k.a. value types).This form can be used to indicate to type checkers that the corresponding
variable or function parameter has a value equivalent to the provided
literal (or one of several literals)::def validate_simple(data: Any) -> Literal[True]: # always returns True ... MODE = Literal['r', 'rb', 'w', 'wb'] def open_helper(file: str, mode: MODE) -> str: ... open_helper('/some/path', 'r') # Passes type check open_helper('/other/path', 'typo') # Error in type checkerLiteral[...] cannot be subclassed. At runtime, an arbitrary value
is allowed as type argument to Literal[...], but type checkers may
impose restrictions.
と言ったふうにヘルプが表示されます。
oct
intを8進数に変換します。
あまり8進数を使う機会がなかったので初めて知ったのですが、
0oというプリフィクスのついた文字列が返ってくるようです。
print(oct(342391)) # 0o1234567
最後まで読んでいただきありがとうございます!