Home > Back-end >  How to skip a value of a class in python
How to skip a value of a class in python

Time:10-15

Class house:
               
     Def __int__(self,width,length,levels):        
     self.width=width
     self.length=Length
     self.levels=levels

Sunlighthouse.house()

Hi there, if you don’t have a value right now, like if you don’t have width data, but want to input a levels data like 3, how do you skip the first two variables and just input the third data value?

Much thanks.

CodePudding user response:

Alternatively you could set default values (not necessarily 0 as below) when you initialize the class then you can set an actual value either when instancing the class or using the instance name. Note be careful with capitals class not Class, def not Def.

class House:
    def __init__(self, width=0, length=0, levels=0):
        self.width = width
        self.length = length
        self.levels = levels


sunlighthouse = House(levels=3)
sunlighthouse.levels = 4

print(sunlighthouse.levels)

CodePudding user response:

I would think maybe just inputting it as an empty string until needed

input_var = house("", "", 62)
  • Related