If you have some useful data in one type of data structure but need it to be in another, it
can be a very quick operation to do the transfer. Indeed, many of the common
transformations between the standard types of data are built into the language. Thus, for
example, with single commands you can convert a floating point number to an integer,
which ignores everything after the decimal point, or convert an unalterable tuple to a
changeable list containing the same elements, or make a number from a text string that
contains digits.
text = ' +0.783 '
floatNumber = float(text)
wholeNumber = int(floatNumber)
dnaTuple = ('A', 'C', 'G', 'T')
dnaList = list(dnaTuple)
Some data type conversions in Python.
Do'stlaringiz bilan baham: