Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python class with optional arguments

class Optioncal_transition(object):
  def __init(self, **args):
    self.chemical = args.get('chemical')
    self.i = args.get('i')
    self.j = args.get('j', self.i)
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: flask get request port 
Python :: covert docx to pdf with libraoffice in python 
Python :: python send image client 
Python :: python "urllib3" download and save pdf 
Python :: tensorflow conv2d 
Python :: typer python 
Python :: pandas cumsum 
Python :: append numeric number in and auto increment in using pandas 
Python :: pyqt5 app styles 
Python :: python sort list by rule 
Python :: permutation and combination in python 
Python :: python integers 
Python :: pipeline model coefficients 
Python :: tkinter window minsize 
Python :: algebraic pyramid python 
Python :: stdin and stdout python 
Python :: Python use number twice without variable 
Python :: Roberta Inference TensorFlow 
Python :: query first 5 element in django 
Python :: pandas drop 1970 
Python :: python C-like structs 
Python :: 20 minute timer with python 
Python :: foreign key django createview 
Python :: python load a txt file and assign a variable 
Python :: looping through the list 
Python :: python 2 print sep end 
Python :: python normalized correlation 
Python :: python code 
Python :: get_or_create in django 
Python :: Python program to print all even numbers in a range 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =