How do I use a keyword as a variable name?

前端 未结 3 519
面向向阳花
面向向阳花 2020-11-30 12:54

I have the following class with the variables from, to and rate. from is a keyword. If I want to use it in the init metho

3条回答
  •  离开以前
    2020-11-30 13:18

    Add a single underscore to your preferred names: from_ and to_

    (see PEP 8)

    class ExchangeRates(JsonAware):
        def __init__(self, from_, to_, rate):
            self.from = from_
            self.to = to_
            self.rate = rate
    

提交回复
热议问题