7/5/2023 0 Comments Python enum![]() Each ‘integer’ string has special properties such as being valid for mathematical calculations. The subset of 6 characters strings that are integers is a relatively small subset. If a six character string represents an integer, then there are only 10^6, or one million possible values. A six character ‘ascii string (128 possible values per character ) has 128^6, or over 4 quadrillion possible values. With the example of an integer converted to a string, every character will be a ‘digit’. This video provides a detailed answer and is worth watching if/when you have the time, and a shorter answer is that storing all data as strings reduces the data. There are advantages not simply treating all data as a string. In fact you could design a language where string is the only type. ![]() Both integer and float as strings are just subsets of all possible strings. Simplistically, the syntax of float is as with an integer with the addition of a single “.” character. Integers are subsets where only numeric characters are allowed. In a sense, all types other than string are subsets of the possible strings. The string is effectively the common representation we could use for all types of data. On this basis there is no need to store values as the previously discussed ‘int’ or ‘float’, and every value, including numbers can be stored as a string. We can store anything, regardless of whether the characters happen to be number or not, so we could even store our numbers as strings. By assigning a number to every possible character, any value we like can reduced to a string of characters, and those characters each stored as a series of numbers. What about all the things that are not normally numbers? Human language in written form represents all values as sequences of characters. Strings: All data can presented, and stored as a string. In fact at the simplest level, we have to types of data: integers and floats which are numbers. To store the value as a number is obvious. Some values, for example a ‘speed’, or a length measurement, just are numbers already. In digital computers, every value becomes a number. 65,535, but what about when you have your own finite set of possibilities, like expressing location as ‘at home’, ‘at work’ or simply ‘elsewhere’? Enter, the Enum.īackground With Digital Data, Everything is a number. TLDR Just read the headings until you find sections of interest.Īscii characters are one of 127 possible characters (although now we use larger character sets), and the original ‘integer’ values were 0,1,2, …. This is a look from the basics to the more advanced in how a dynamic language like python treats enum, through the advanced treatment available in kotlin. The overall concept is processing information where each value is one of a very limited set of values. Enum is an abbreviation for ‘enumerated’.
0 Comments
Leave a Reply. |