Detailed Print – CSKC
Sign In

Search

siteicon
Code Learning#PYTHON#9411 Back

Mixed data types

Both list and tuple can support the mixed data types. We also call it the heterogeneous type of data. In this example the list contains data of string, integer, float and boolean types. This program also shows an example of how tuple is used for cases where non-changeable data is used.

Source Code

		 

Click to open popup

Run Output

Name    Age     Height  GradStat
--------------------------------
RAVI 23 1.63 True
VISHAL 19 1.72 False

Notes

  • Like the list[], tuple can also contain the mixed data types.
  • Python documentation however suggests that for list homogeneous type of data is preferable for better performance.
  • Python lists look quite like arrays and can be used wherever arrays are used in other language programs. However if you want higher performance of homogeneous arrays we may need to use the external libraries like NumPy or the array module as provided by the importable modules of python.


Suggested Filename(s): mixed-data-type,py