Default Value
It is recommended to assign default value as per your program need while creating variable.
In different context, C-style programming language has concept of auto assignment of default value in certain scenarios and garbage value comes in picture in different scenarios. In python, you do not need to declare variable separately. So, default value would not come from python, rather it would come from programmer.
General approach
Note: This is general approach. Please judge if its matching with your program need.Data Type | Default value can be... |
---|---|
bool | As per need |
int | 0 or As per need |
float | 0.0 or As per need |
list | [ ] or list() or As per need |
tuple | ( ) or tuple() or As per need |
array | empty array or As per need |
set | set() or As per need |
dict | { } or dict() or As per need |
# Example, Default value for bool, int, float, list, tuple, array, set, dictionary
my_bool = False
my_bool = True
my_int = 0
my_int = int()
my_float = 0.0
my_float = float()
my_list = []
my_list = list()
my_tuple = ()
my_tuple = tuple()
import array
my_array = array.array( 'i')
my_set = set()
my_dict = {}
my_dict = dict()