Numeric Data types There are three different data types to store numeric data. int float complex int (integer) Data type 'int' is used to hold the whole numbers (i.e., no decimal positions). This number can either be positive or negative. 1 2 3 4 5 6 7 # int - used to hold whole numbers # Positive numbers positive_number = 1 # Negative numbers negative_number = - 2 It is possible that an integer data can be stored in a string and we might need to convert it to the int type. We can do that using built-in method int(). 1 2 3 4 # String to int number_as_string = "10" number = int (number_as_string) int() method can also be used to convert floating point numbers to integer. This removes any decimal values and moves whole number to integer variable. 1 2 3 4 5 6 7 # Float to int float_value = 10.0 number = int (float_value) # 10 float_value = 10.50 number = int (float_value) # 10 float (floating point numbers) Data type 'float' is used to hold the floating
Code with PR - Technical tips on coding and more...