5g to kg code example Example 1: grams in kg def kg_to_g(kg): return kg*1000 Example 2: 1g to kg 1g = 0.001kg