Data Types
Data Types
I’m writing a guide on python programming, but first I think we should get some theory out of the way first. Data types are fundamental to programming. Mismatched data types can either throw errors or cause the program to act in an unpredictable way.
Integer:
An ‘integer’ is a whole number. It can be greater than, less than, or equal to 0. 9 is an integer, as is -9, as is 42, etc. Integers are often shortened to just ‘int’.
Float:
Whereas an int is a whole number, a float can be represented as a fraction. Examples of floats include 2/3, 0.75, and 3.14. Like integers, floats can be positive or negative.
Character:
A character can be a letter (”a”), a punctuation mark (”!”), a symbol, or a character representation of a number (the character “2” is different to the integer 2 for reasons I will discuss later but boil down to binary) . Like int, character is often shortened to “char”.
String:
A string is a series of characters. The typical example of a string used in programming is “hello, world!”. Strings work similarly to arrays, and can be worked with in much the same way. I will talk about this more on a guide about arrays, but for now just know that a string is a sequence of characters.
Boolean:
A boolean is probably the simplest data type. There are only two options: True or False; 1 or 0; On or Off.
Over time in my python tutorial I will give examples of how to work with these data types, as well as common errors and how to fix them.