Python 3 Conversion between Scalar Built in Types
The type conversion in Python 3 is explained with the code below,
The type conversion in Python 3 is explained with the code below,
"Conversion between the types"
int_value = 100 # An integer assignment
float_value = 100.0 # A floating point
string_value = "name" # A string#
none_value = None
print (int_value) #100
print (float(int_value)) #100.0
print (str(int_value)) #100
print (float_value) #100.0
print (int(float_value)) #100
print (str(float_value)) #100.0
print (string_value) #name
# print (int(string_value))
# ValueError: invalid literal for int() with base 10: 'name'#
print (float(string_value))
# ValueError: could not convert string to float: 'name'
No comments:
Post a Comment