How can I create empty variable that has the same data type of another variable?
data = get_data()
new_variable = data.data_type() #just create empty variable
In the above case, if data
is a list then new_variable
will be list()
Get the class of the value, invoke the constructor with no arguments, and hope that it doesn't blow up.
data.__class__()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With