In C, variables must be a specified data type and they need format specifiers to be printed.
Data Type | Size | Description |
---|---|---|
int | 2 or 4 bytes | stores whole numbers |
float | 4 bytes | stores fractional numbers up to 7 decimal digits |
double | 8 bytes | stores fractional numbers up to 15 decimal digits |
char | 1 byte | a single character / letter / number / ASCII value |
long | 8 bytes | stores whole numbers, can go higher than int |
bool | 2 bytes | stores 'true' or 'false' values |
Format Specifier | Data Type |
---|---|
%d or %i | int |
%f | float |
%1f | double |
%c | char |
%s | strings |
- '+' for addition
- '-' for substraction
- '*' for multiplication
- '/' for division
- '%' for remainder
C also supports syntactic sugar, or shorthand expressions for the same functionality. We could equivalently say counter += 1;
to add one to counter before storing it again. We could also just write counter++
or counter--
.
In Python, variables don't need a specified data type or a format specifier to pe printed. A variable is created when first assigning a value to it.
Data Type | Size | Description |
---|---|---|
int | 28 bytes | stores whole numbers |
float | 24 bytes | stores fractional numbers |
bool | 28 bytes | stores 'True' or 'False' values |
string | 49 bytes | +1 byte for each character |
Besides the previously mentioned data types, Python also has as built-in types:
- complex - numeric type that returns a complex number by specifing a real number and an imaginary number.
- list - sequence type that stores ordered, changeable, and duplicate items.
- tuple - sequence type that stores multiple items that are ordered, unchangeable and duplicate.
- set - set type that stores unordered, unchangeable and don't allow duplicates.
- dict - mapping type that stores ordered, changeable, and don't allow duplicates. Stores data in key - value pairs.
- range - sequence type returns a sequence of numbers.
Similar to C, Python also supports syntactic sugar, although only the expression counter += 1
.