Variables and constants in Python
Data types
Data typesA data type is the characteristic of a variable that determines what type of data it can hold. The following table explains different data types and gives an example of each.
Python supports the following simple data types for variables and constants:
Boolean A Boolean can either be When evaluating whether something is Integer An integer is a positive or negative whole number, e.g. Floating-point (or float) A floating-point, or a float, is a number with a decimal point or an exponential in it, e.g. String Strings are text or words – a 'string' of characters. A string is made up of zero or more characters that have been declared with either single or double quotes around them, e.g. A note on data types for numeric values To decide whether a numeric value should be an int or float, or a string, think about how the number will be used. If it represents a measurement or a count of something, then it should be an int or a float. If it is a number that won't be used in calculations – e.g. an ID number, a phone number, a registration number or street number – then it should be stored as a string. This is particularly important for numbers that might have a leading zero that needs to be preserved (e.g. bank account numbers: 0123456, phone numbers: 0400999000, and post codes: 0123) or that might contain other characters, including spaces (e.g. phone numbers: +61 9999 0000, (03)9999-0000 etc.). These numbers should be stored as strings. Char Many other programming languages have a data type called char, which is a single character, e.g. |