Three important commands in Python: dir(object), type(object), and help(object)

Python

Programming in Python, we meet three important commands: dir(), type(), and help(). To see how they work, we are going to use three types: int, “Jacek” i bool.

Programując w Pythonie musieliśmy zetknąć się z trzema ważnymi poleceniami: dir(), type() i help(). W celu ich wypróbowania użyjemy trzech typów: int, “Jacek” i bool.

dir()

>>> dir(int)
[‘__abs__’, ‘__add__’, ‘__and__’, ‘__bool__’, ‘__ceil__’, ‘__class__’, ‘__delatt
r__’, ‘__dir__’, ‘__divmod__’, ‘__doc__’, ‘__eq__’, ‘__float__’, ‘__floor__’, ‘_
_floordiv__’, ‘__format__’, ‘__ge__’, ‘__getattribute__’, ‘__getnewargs__’, ‘__g
t__’, ‘__hash__’, ‘__index__’, ‘__init__’, ‘__int__’, ‘__invert__’, ‘__le__’, ‘_
_lshift__’, ‘__lt__’, ‘__mod__’, ‘__mul__’, ‘__ne__’, ‘__neg__’, ‘__new__’, ‘__o
r__’, ‘__pos__’, ‘__pow__’, ‘__radd__’, ‘__rand__’, ‘__rdivmod__’, ‘__reduce__’,
‘__reduce_ex__’, ‘__repr__’, ‘__rfloordiv__’, ‘__rlshift__’, ‘__rmod__’, ‘__rmu
l__’, ‘__ror__’, ‘__round__’, ‘__rpow__’, ‘__rrshift__’, ‘__rshift__’, ‘__rsub__
‘, ‘__rtruediv__’, ‘__rxor__’, ‘__setattr__’, ‘__sizeof__’, ‘__str__’, ‘__sub__’
, ‘__subclasshook__’, ‘__truediv__’, ‘__trunc__’, ‘__xor__’, ‘bit_length’, ‘conj
ugate’, ‘denominator’, ‘from_bytes’, ‘imag’, ‘numerator’, ‘real’, ‘to_bytes’]
>>> dir(“Jacek”)
[‘__add__’, ‘__class__’, ‘__contains__’, ‘__delattr__’, ‘__dir__’, ‘__doc__’, ‘_
_eq__’, ‘__format__’, ‘__ge__’, ‘__getattribute__’, ‘__getitem__’, ‘__getnewargs
__’, ‘__gt__’, ‘__hash__’, ‘__init__’, ‘__iter__’, ‘__le__’, ‘__len__’, ‘__lt__’
, ‘__mod__’, ‘__mul__’, ‘__ne__’, ‘__new__’, ‘__reduce__’, ‘__reduce_ex__’, ‘__r
epr__’, ‘__rmod__’, ‘__rmul__’, ‘__setattr__’, ‘__sizeof__’, ‘__str__’, ‘__subcl
asshook__’, ‘capitalize’, ‘casefold’, ‘center’, ‘count’, ‘encode’, ‘endswith’, ‘
expandtabs’, ‘find’, ‘format’, ‘format_map’, ‘index’, ‘isalnum’, ‘isalpha’, ‘isd
ecimal’, ‘isdigit’, ‘isidentifier’, ‘islower’, ‘isnumeric’, ‘isprintable’, ‘issp
ace’, ‘istitle’, ‘isupper’, ‘join’, ‘ljust’, ‘lower’, ‘lstrip’, ‘maketrans’, ‘pa
rtition’, ‘replace’, ‘rfind’, ‘rindex’, ‘rjust’, ‘rpartition’, ‘rsplit’, ‘rstrip
‘, ‘split’, ‘splitlines’, ‘startswith’, ‘strip’, ‘swapcase’, ‘title’, ‘translate
‘, ‘upper’, ‘zfill’]
>>> dir(bool)
[‘__abs__’, ‘__add__’, ‘__and__’, ‘__bool__’, ‘__ceil__’, ‘__class__’, ‘__delatt
r__’, ‘__dir__’, ‘__divmod__’, ‘__doc__’, ‘__eq__’, ‘__float__’, ‘__floor__’, ‘_
_floordiv__’, ‘__format__’, ‘__ge__’, ‘__getattribute__’, ‘__getnewargs__’, ‘__g
t__’, ‘__hash__’, ‘__index__’, ‘__init__’, ‘__int__’, ‘__invert__’, ‘__le__’, ‘_
_lshift__’, ‘__lt__’, ‘__mod__’, ‘__mul__’, ‘__ne__’, ‘__neg__’, ‘__new__’, ‘__o
r__’, ‘__pos__’, ‘__pow__’, ‘__radd__’, ‘__rand__’, ‘__rdivmod__’, ‘__reduce__’,
‘__reduce_ex__’, ‘__repr__’, ‘__rfloordiv__’, ‘__rlshift__’, ‘__rmod__’, ‘__rmu
l__’, ‘__ror__’, ‘__round__’, ‘__rpow__’, ‘__rrshift__’, ‘__rshift__’, ‘__rsub__
‘, ‘__rtruediv__’, ‘__rxor__’, ‘__setattr__’, ‘__sizeof__’, ‘__str__’, ‘__sub__’
, ‘__subclasshook__’, ‘__truediv__’, ‘__trunc__’, ‘__xor__’, ‘bit_length’, ‘conj
ugate’, ‘denominator’, ‘from_bytes’, ‘imag’, ‘numerator’, ‘real’, ‘to_bytes’]
>>>

So we can see that the command dir() is simply a listing of functions and methods for each type in Python. Names with underscores are useful for operator overloading in classes (they represent the implementation of the string object and are needed for customization). Names without scores are the methods on string objects.

We know that they are different, so the functions and methods are different too. Methods are names with two underscores in the beginning and in the end of them. The rest of the names are functions. For the people who are dealing with Linux/Unix operating systems “dir” is well-known command.

int and bool are built-in types, but “Jacek” is rather a value of string type. Instead of “Jacek”, we can write simply dir(string) and…

>>> dir(string)
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
NameError: name ‘string’ is not defined

We have a problem! We should import string:

>>> import string
>>> dir(string)
[‘ChainMap’, ‘Formatter’, ‘Template’, ‘_TemplateMetaclass’, ‘__builtins__’, ‘__c
ached__’, ‘__doc__’, ‘__file__’, ‘__initializing__’, ‘__loader__’, ‘__name__’, ‘
__package__’, ‘_re’, ‘_string’, ‘ascii_letters’, ‘ascii_lowercase’, ‘ascii_upper
case’, ‘capwords’, ‘digits’, ‘hexdigits’, ‘octdigits’, ‘printable’, ‘punctuation
‘, ‘whitespace’]
>>>

Yes, now we can see all what we need, but… the methods and functions are different than the those of “Jacek”. Why? We know “Jacek” is string. We should be sure if “Jacek” is really string:

>>> type(“Jacek”)
<class ‘str’>
>>>

The type is str not string. It’s the same for us, but not for our Python. Do not take string into your consideration.

>>> dir(str)
[‘__add__’, ‘__class__’, ‘__contains__’, ‘__delattr__’, ‘__dir__’, ‘__doc__’, ‘_
_eq__’, ‘__format__’, ‘__ge__’, ‘__getattribute__’, ‘__getitem__’, ‘__getnewargs
__’, ‘__gt__’, ‘__hash__’, ‘__init__’, ‘__iter__’, ‘__le__’, ‘__len__’, ‘__lt__’
, ‘__mod__’, ‘__mul__’, ‘__ne__’, ‘__new__’, ‘__reduce__’, ‘__reduce_ex__’, ‘__r
epr__’, ‘__rmod__’, ‘__rmul__’, ‘__setattr__’, ‘__sizeof__’, ‘__str__’, ‘__subcl
asshook__’, ‘capitalize’, ‘casefold’, ‘center’, ‘count’, ‘encode’, ‘endswith’, ‘
expandtabs’, ‘find’, ‘format’, ‘format_map’, ‘index’, ‘isalnum’, ‘isalpha’, ‘isd
ecimal’, ‘isdigit’, ‘isidentifier’, ‘islower’, ‘isnumeric’, ‘isprintable’, ‘issp
ace’, ‘istitle’, ‘isupper’, ‘join’, ‘ljust’, ‘lower’, ‘lstrip’, ‘maketrans’, ‘pa
rtition’, ‘replace’, ‘rfind’, ‘rindex’, ‘rjust’, ‘rpartition’, ‘rsplit’, ‘rstrip
‘, ‘split’, ‘splitlines’, ‘startswith’, ‘strip’, ‘swapcase’, ‘title’, ‘translate
‘, ‘upper’, ‘zfill’]

>>>

We have the same methods and functions like those of “Jacek”, so “Jacek” == str.

type()

>>> type(int)
<class ‘type’>
>>> type(“Jacek”)
<class ‘str’>
>>> type(bool)
<class ‘type’>
>>>

Let’s check the type of our built-ins. We can see int and bool is type, but not “Jacek”. Why? We should check str:

>>> type(str)
<class ‘type’>

Yes, we can see that str is also type. Taking all into consideration, we can say that type is common for the built-ins in our Python. It’s the base for them, in other words. Let’s see the diagram:

“Jacek”

————————————————————————————–

int                                              str                                               bool

————————————————————————————–

type

Now it’s clear.

help()

>>> help(int)
Help on class int in module builtins:

class int(object)
|  int(x[, base]) -> integer
|
|  Convert a string or number to an integer, if possible.  A floating
|  point argument will be truncated towards zero (this does not include a
|  string representation of a floating point number!)  When converting a
|  string, use the optional base.  It is an error to supply a base when
|  converting a non-string.
|
|  Methods defined here:
|
|  __abs__(…)
|      x.__abs__() <==> abs(x)
|
|  __add__(…)
|      x.__add__(y) <==> x+y
|
|  __and__(…)
|      x.__and__(y) <==> x&y
|
|  __bool__(…)
|      x.__bool__() <==> x != 0
|
|  __ceil__(…)
|      Ceiling of an Integral returns itself.
|
|  __divmod__(…)
|      x.__divmod__(y) <==> divmod(x, y)
|
|  __eq__(…)
|      x.__eq__(y) <==> x==y
|
|  __float__(…)
|      x.__float__() <==> float(x)
|
|  __floor__(…)
|      Flooring an Integral returns itself.
|
|  __floordiv__(…)
|      x.__floordiv__(y) <==> x//y
|
|  __format__(…)
|
|  __ge__(…)
|      x.__ge__(y) <==> x>=y
|
|  __getattribute__(…)
|      x.__getattribute__(‘name’) <==> x.name
|
|  __getnewargs__(…)
|
|  __gt__(…)
|      x.__gt__(y) <==> x>y
|
|  __hash__(…)
|      x.__hash__() <==> hash(x)
|
|  __index__(…)
|      x[y:z] <==> x[y.__index__():z.__index__()]
|
|  __int__(…)
|      x.__int__() <==> int(x)
|
|  __invert__(…)
|      x.__invert__() <==> ~x
|
|  __le__(…)
|      x.__le__(y) <==> x<=y
|
|  __lshift__(…)
|      x.__lshift__(y) <==> x<<y
|
|  __lt__(…)
|      x.__lt__(y) <==> x<y
|
|  __mod__(…)
|      x.__mod__(y) <==> x%y
|
|  __mul__(…)
|      x.__mul__(y) <==> x*y
|
|  __ne__(…)
|      x.__ne__(y) <==> x!=y
|
|  __neg__(…)
|      x.__neg__() <==> -x
|
|  __or__(…)
|      x.__or__(y) <==> x|y
|
|  __pos__(…)
|      x.__pos__() <==> +x
|
|  __pow__(…)
|      x.__pow__(y[, z]) <==> pow(x, y[, z])
|
|  __radd__(…)
|      x.__radd__(y) <==> y+x
|
|  __rand__(…)
|      x.__rand__(y) <==> y&x
|
|  __rdivmod__(…)
|      x.__rdivmod__(y) <==> divmod(y, x)
|
|  __repr__(…)
|      x.__repr__() <==> repr(x)
|
|  __rfloordiv__(…)
|      x.__rfloordiv__(y) <==> y//x
|
|  __rlshift__(…)
|      x.__rlshift__(y) <==> y<<x
|
|  __rmod__(…)
|      x.__rmod__(y) <==> y%x
|
|  __rmul__(…)
|      x.__rmul__(y) <==> y*x
|
|  __ror__(…)
|      x.__ror__(y) <==> y|x
|
|  __round__(…)
|      Rounding an Integral returns itself.
|      Rounding with an ndigits argument also returns an integer.
|
|  __rpow__(…)
|      y.__rpow__(x[, z]) <==> pow(x, y[, z])
|
|  __rrshift__(…)
|      x.__rrshift__(y) <==> y>>x
|
|  __rshift__(…)
|      x.__rshift__(y) <==> x>>y
|
|  __rsub__(…)
|      x.__rsub__(y) <==> y-x
|
|  __rtruediv__(…)
|      x.__rtruediv__(y) <==> y/x
|
|  __rxor__(…)
|      x.__rxor__(y) <==> y^x
|
|  __sizeof__(…)
|      Returns size in memory, in bytes
|
|  __str__(…)
|      x.__str__() <==> str(x)
|
|  __sub__(…)
|      x.__sub__(y) <==> x-y
|
|  __truediv__(…)
|      x.__truediv__(y) <==> x/y
|
|  __trunc__(…)
|      Truncating an Integral returns itself.
|
|  __xor__(…)
|      x.__xor__(y) <==> x^y
|
|  bit_length(…)
|      int.bit_length() -> int
|
|      Number of bits necessary to represent self in binary.
|      >>> bin(37)
|      ‘0b100101’
|      >>> (37).bit_length()
|      6
|
|  conjugate(…)
|      Returns self, the complex conjugate of any int.
|
|  from_bytes(…)
|      int.from_bytes(bytes, byteorder, *, signed=False) -> int
|
|      Return the integer represented by the given array of bytes.
|
|      The bytes argument must either support the buffer protocol or be an
|      iterable object producing bytes.  Bytes and bytearray are examples of
|      built-in objects that support the buffer protocol.
|
|      The byteorder argument determines the byte order used to represent the
|      integer.  If byteorder is ‘big’, the most significant byte is at the
|      beginning of the byte array.  If byteorder is ‘little’, the most
|      significant byte is at the end of the byte array.  To request the native
|      byte order of the host system, use `sys.byteorder’ as the byte order val
ue.
|
|      The signed keyword-only argument indicates whether two’s complement is
|      used to represent the integer.
|
|  to_bytes(…)
|      int.to_bytes(length, byteorder, *, signed=False) -> bytes
|
|      Return an array of bytes representing an integer.
|
|      The integer is represented using length bytes.  An OverflowError is
|      raised if the integer is not representable with the given number of
|      bytes.
|
|      The byteorder argument determines the byte order used to represent the
|      integer.  If byteorder is ‘big’, the most significant byte is at the
|      beginning of the byte array.  If byteorder is ‘little’, the most
|      significant byte is at the end of the byte array.  To request the native
|      byte order of the host system, use `sys.byteorder’ as the byte order val
ue.
|
|      The signed keyword-only argument determines whether two’s complement is
|      used to represent the integer.  If signed is False and a negative intege
r
|      is given, an OverflowError is raised.
|
|  ———————————————————————-
|  Data descriptors defined here:
|
|  denominator
|      the denominator of a rational number in lowest terms
|
|  imag
|      the imaginary part of a complex number
|
|  numerator
|      the numerator of a rational number in lowest terms
|
|  real
|      the real part of a complex number
|
|  ———————————————————————-
|  Data and other attributes defined here:
|
|  __new__ = <built-in method __new__ of type object>
|      T.__new__(S, …) -> a new object with type S, a subtype of T

>>> help(“Jacek”)
no Python documentation found for ‘Jacek’

>>> help(bool)
Help on class bool in module builtins:

class bool(int)
|  bool(x) -> bool
|
|  Returns True when the argument x is true, False otherwise.
|  The builtins True and False are the only two instances of the class bool.
|  The class bool is a subclass of the class int, and cannot be subclassed.
|
|  Method resolution order:
|      bool
|      int
|      object
|
|  Methods defined here:
|
|  __and__(…)
|      x.__and__(y) <==> x&y
|
|  __or__(…)
|      x.__or__(y) <==> x|y
|
|  __rand__(…)
|      x.__rand__(y) <==> y&x
|
|  __repr__(…)
|      x.__repr__() <==> repr(x)
|
|  __ror__(…)
|      x.__ror__(y) <==> y|x
|
|  __rxor__(…)
|      x.__rxor__(y) <==> y^x
|
|  __str__(…)
|      x.__str__() <==> str(x)
|
|  __xor__(…)
|      x.__xor__(y) <==> x^y
|
|  ———————————————————————-
|  Data and other attributes defined here:
|
|  __new__ = <built-in method __new__ of type object>
|      T.__new__(S, …) -> a new object with type S, a subtype of T
|
|  ———————————————————————-
|  Methods inherited from int:
|
|  __abs__(…)
|      x.__abs__() <==> abs(x)
|
|  __add__(…)
|      x.__add__(y) <==> x+y
|
|  __bool__(…)
|      x.__bool__() <==> x != 0
|
|  __ceil__(…)
|      Ceiling of an Integral returns itself.
|
|  __divmod__(…)
|      x.__divmod__(y) <==> divmod(x, y)
|
|  __eq__(…)
|      x.__eq__(y) <==> x==y
|
|  __float__(…)
|      x.__float__() <==> float(x)
|
|  __floor__(…)
|      Flooring an Integral returns itself.
|
|  __floordiv__(…)
|      x.__floordiv__(y) <==> x//y
|
|  __format__(…)
|
|  __ge__(…)
|      x.__ge__(y) <==> x>=y
|
|  __getattribute__(…)
|      x.__getattribute__(‘name’) <==> x.name
|
|  __getnewargs__(…)
|
|  __gt__(…)
|      x.__gt__(y) <==> x>y
|
|  __hash__(…)
|      x.__hash__() <==> hash(x)
|
|  __index__(…)
|      x[y:z] <==> x[y.__index__():z.__index__()]
|
|  __int__(…)
|      x.__int__() <==> int(x)
|
|  __invert__(…)
|      x.__invert__() <==> ~x
|
|  __le__(…)
|      x.__le__(y) <==> x<=y
|
|  __lshift__(…)
|      x.__lshift__(y) <==> x<<y
|
|  __lt__(…)
|      x.__lt__(y) <==> x<y
|
|  __mod__(…)
|      x.__mod__(y) <==> x%y
|
|  __mul__(…)
|      x.__mul__(y) <==> x*y
|
|  __ne__(…)
|      x.__ne__(y) <==> x!=y
|
|  __neg__(…)
|      x.__neg__() <==> -x
|
|  __pos__(…)
|      x.__pos__() <==> +x
|
|  __pow__(…)
|      x.__pow__(y[, z]) <==> pow(x, y[, z])
|
|  __radd__(…)
|      x.__radd__(y) <==> y+x
|
|  __rdivmod__(…)
|      x.__rdivmod__(y) <==> divmod(y, x)
|
|  __rfloordiv__(…)
|      x.__rfloordiv__(y) <==> y//x
|
|  __rlshift__(…)
|      x.__rlshift__(y) <==> y<<x
|
|  __rmod__(…)
|      x.__rmod__(y) <==> y%x
|
|  __rmul__(…)
|      x.__rmul__(y) <==> y*x
|
|  __round__(…)
|      Rounding an Integral returns itself.
|      Rounding with an ndigits argument also returns an integer.
|
|  __rpow__(…)
|      y.__rpow__(x[, z]) <==> pow(x, y[, z])
|
|  __rrshift__(…)
|      x.__rrshift__(y) <==> y>>x
|
|  __rshift__(…)
|      x.__rshift__(y) <==> x>>y
|
|  __rsub__(…)
|      x.__rsub__(y) <==> y-x
|
|  __rtruediv__(…)
|      x.__rtruediv__(y) <==> y/x
|
|  __sizeof__(…)
|      Returns size in memory, in bytes
|
|  __sub__(…)
|      x.__sub__(y) <==> x-y
|
|  __truediv__(…)
|      x.__truediv__(y) <==> x/y
|
|  __trunc__(…)
|      Truncating an Integral returns itself.
|
|  bit_length(…)
|      int.bit_length() -> int
|
|      Number of bits necessary to represent self in binary.
|      >>> bin(37)
|      ‘0b100101’
|      >>> (37).bit_length()
|      6
|
|  conjugate(…)
|      Returns self, the complex conjugate of any int.
|
|  from_bytes(…)
|      int.from_bytes(bytes, byteorder, *, signed=False) -> int
|
|      Return the integer represented by the given array of bytes.
|
|      The bytes argument must either support the buffer protocol or be an
|      iterable object producing bytes.  Bytes and bytearray are examples of
|      built-in objects that support the buffer protocol.
|
|      The byteorder argument determines the byte order used to represent the
|      integer.  If byteorder is ‘big’, the most significant byte is at the
|      beginning of the byte array.  If byteorder is ‘little’, the most
|      significant byte is at the end of the byte array.  To request the native
|      byte order of the host system, use `sys.byteorder’ as the byte order val
ue.
|
|      The signed keyword-only argument indicates whether two’s complement is
|      used to represent the integer.
|
|  to_bytes(…)
|      int.to_bytes(length, byteorder, *, signed=False) -> bytes
|
|      Return an array of bytes representing an integer.
|
|      The integer is represented using length bytes.  An OverflowError is
|      raised if the integer is not representable with the given number of
|      bytes.
|
|      The byteorder argument determines the byte order used to represent the
|      integer.  If byteorder is ‘big’, the most significant byte is at the
|      beginning of the byte array.  If byteorder is ‘little’, the most
|      significant byte is at the end of the byte array.  To request the native
|      byte order of the host system, use `sys.byteorder’ as the byte order val
ue.
|
|      The signed keyword-only argument determines whether two’s complement is
|      used to represent the integer.  If signed is False and a negative intege
r
|      is given, an OverflowError is raised.
|
|  ———————————————————————-
|  Data descriptors inherited from int:
|
|  denominator
|      the denominator of a rational number in lowest terms
|
|  imag
|      the imaginary part of a complex number
|
|  numerator
|      the numerator of a rational number in lowest terms
|
|  real
|      the real part of a complex number

>>>

This command provides us with help. And we can see what the given object can do and we can do with it. We can see a short description of a command and how to use a method or function. And again, we can’t get help for “Jacek” (help(“Jacek”)), but we can use that:

>>> help(str)
Help on class str in module builtins:

class str(object)
|  str(object[, encoding[, errors]]) -> str
|
|  Create a new string object from the given object. If encoding or
|  errors is specified, then the object must expose a data buffer
|  that will be decoded using the given encoding and error handler.
|  Otherwise, returns the result of object.__str__() (if defined)
|  or repr(object).
|  encoding defaults to sys.getdefaultencoding().
|  errors defaults to ‘strict’.
|
|  Methods defined here:
|
|  __add__(…)
|      x.__add__(y) <==> x+y
|
|  __contains__(…)
|      x.__contains__(y) <==> y in x
|
|  __eq__(…)
|      x.__eq__(y) <==> x==y
|
|  __format__(…)
|      S.__format__(format_spec) -> str
|
|      Return a formatted version of S as described by format_spec.
|
|  __ge__(…)
|      x.__ge__(y) <==> x>=y
|
|  __getattribute__(…)
|      x.__getattribute__(‘name’) <==> x.name
|
|  __getitem__(…)
|      x.__getitem__(y) <==> x[y]
|
|  __getnewargs__(…)
|
|  __gt__(…)
|      x.__gt__(y) <==> x>y
|
|  __hash__(…)
|      x.__hash__() <==> hash(x)
|
|  __iter__(…)
|      x.__iter__() <==> iter(x)
|
|  __le__(…)
|      x.__le__(y) <==> x<=y
|
|  __len__(…)
|      x.__len__() <==> len(x)
|
|  __lt__(…)
|      x.__lt__(y) <==> x<y
|
|  __mod__(…)
|      x.__mod__(y) <==> x%y
|
|  __mul__(…)
|      x.__mul__(n) <==> x*n
|
|  __ne__(…)
|      x.__ne__(y) <==> x!=y
|
|  __repr__(…)
|      x.__repr__() <==> repr(x)
|
|  __rmod__(…)
|      x.__rmod__(y) <==> y%x
|
|  __rmul__(…)
|      x.__rmul__(n) <==> n*x
|
|  __sizeof__(…)
|      S.__sizeof__() -> size of S in memory, in bytes
|
|  __str__(…)
|      x.__str__() <==> str(x)
|
|  capitalize(…)
|      S.capitalize() -> str
|
|      Return a capitalized version of S, i.e. make the first character
|      have upper case and the rest lower case.
|
|  casefold(…)
|      S.casefold() -> str
|
|      Return a version of S suitable for caseless comparisons.
|
|  center(…)
|      S.center(width[, fillchar]) -> str
|
|      Return S centered in a string of length width. Padding is
|      done using the specified fill character (default is a space)
|
|  count(…)
|      S.count(sub[, start[, end]]) -> int
|
|      Return the number of non-overlapping occurrences of substring sub in
|      string S[start:end].  Optional arguments start and end are
|      interpreted as in slice notation.
|
|  encode(…)
|      S.encode(encoding=’utf-8′, errors=’strict’) -> bytes
|
|      Encode S using the codec registered for encoding. Default encoding
|      is ‘utf-8’. errors may be given to set a different error
|      handling scheme. Default is ‘strict’ meaning that encoding errors raise
|      a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and
|      ‘xmlcharrefreplace’ as well as any other name registered with
|      codecs.register_error that can handle UnicodeEncodeErrors.
|
|  endswith(…)
|      S.endswith(suffix[, start[, end]]) -> bool
|
|      Return True if S ends with the specified suffix, False otherwise.

We can see that these three commands are very useful, and they can provide us with interesting information about our objects.

Leave a comment