[PYTHON] Determine if the member should be set to the default string with just the or operator

If you look at source of openpyxl, ```or` Make a note of some brilliant idioms that use the `` operator on strings.

In the self.title = title or self._default_title part of the code below, if the argument title of __init__ is None or an empty string, the value of the class variable _default_title " Sheet " is set to self.title as the default string.

child.py


class _WorkbookChild(object):

    __title = ""
    _id = None
    _path = "{0}"
    __parent = None
    _default_title = "Sheet"

    def __init__(self, parent=None, title=None):
        self.__parent = parent
        self.title = title or self._default_title
        self.HeaderFooter = HeaderFooter()

Addendum) There was a detailed explanation in this article. http://qiita.com/keisuke-nakata/items/e0598b2c13807f102469

Recommended Posts

Determine if the member should be set to the default string with just the or operator
Determine if the string is formatable
Have python check if the string can be converted / converted to int
[Python] Round up with just the operator
Play with machine learning: Can Q-Learning determine if marketing-related actions should be taken?
How to Learn Kaldi with the JUST Corpus
Change the string to be replaced according to the matched string by replacing with Python regular expression
How to delete the specified string with the sed command! !! !!
Just add the driver to the shape key with blender