PYTHON_101 | VALUES & VARIABLES TYPES
SMARS Learning Platform
36% Complete
PYTHON_101 | VALUES & VARIABLES TYPES
Programs often need to work with numbers and text, adding and subtracting, asking questions and processing answers.
Python is able to label different types of values so that it can make different commands available to us.
The different types of values are listed below:
Value Types | Description | Example |
---|---|---|
integer |
A whole number, which can be positive or negative | 1, 2, 3, 4, -500, 1000 |
float |
A decimal number, which can be positive or negative | 3.14, -2.5, 1.66666 |
string |
A line of text | 'hello world', 'my name is Kevin' |
list |
A collection of words or numbers, or objects | [‘cat’,’dog’,’fish’,’gecko’], or [1,2,3,5,8,13,21] |
dict |
A dictionary - a list, with pairs of values | {‘name’:’Kevin’, ‘address’:’UK’, ‘age’:45} |
object |
An instance of a class (we’ll cover this in a later session) | Object of 'Cat' Class |
When we assign a value to a variable, it is said to have the a type. e.g.
a = 1
b = 2.1
c = "hello"
In this example a
contains the value 1
and is of type integer
, b
contains the value 2.1
and is of type float
(because it has a decimal point), and c
contains hello
and is of type string
because it contains a text wrapped inside some speech marks.