Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python class optional arguments

class Point:
    def __init__(self, x, y, z = 0):
        self.x = x
        self.y = y
        self.z = z
    
    def __str__(self):
        return f"X: {self.x}, Y: {self.y}, Z:{self.z}"

print(Point(1, 2)) # Object 1
print(Point(54, 92, 0)) # Object 2
print(Point(99, 26, 100)) # Object 3


# Output:

# X: 1, Y: 2, Z:0
# X: 54, Y: 92, Z:0
# X: 99, Y: 26, Z:100
Source by www.delftstack.com #
 
PREVIOUS NEXT
Tagged: #python #class #optional #arguments
ADD COMMENT
Topic
Name
9+8 =