( ̄︶ ̄)↗ Basic Data Types
Numbers
Integer (int())
: a python data type for whole numbers.
Float (float())
: a python data type for decimal numbers.
(also Booleans (bool())
, but we'll get on to them a bit later)
Other ways to record numerical data
- Binary
(bin())
is how computers best process information using 1's and 0's, to the power of 2. - Hexadecimal
(hex())
is a mixture of numbers and letters and is used to condense binary code and data, to the power of 16. - Octal numbers
(oct())
also condenses data to the power of 8.
Strings
String: a string is a python data type for text and characters contained within either "" or ''.
Using "speech marks" might be better to avoid confusing Python. If apostrophes are used during a word then the whole string may be misread, for example;
print('it wasn't what I needed')
Python has misinterpreted the apostrophe in the word 'wasn't' as an instruction to end the string.
Strings can have spaces within them but variables need ‘_’ i.e snake_case (common practice) to define a space; variable_name = value
Variables are labels used to define the value of the data stored within them. Variable names and values are connected with the = sign. Variable names cannot start with a number but can include numbers i.e.
student_1 = Casey
Algorithmic Operator Types
- + add
- - subtract
- * multiply
- / division
- ** exponent
- % modulo (remainder)
The * and + operators work on strings as well as integers. the * will repeat a string and the + will join the two words together. This is called concatenation.
Top comments (1)
hi