Data types and Operators

Every value is stored as a particular data type. Some of the simple data types you need to know are:

  • Integer
  • Real
  • String
  • Boolean

The following video clip describes what these are.

Examples

Examples of strings are: "Hello", "Goodbye".

  • To input a string, use input()

Examples of integers are: 2, 6, -89, 45421.

  • To input an integer at the screen, use int(input())

Examples of reals are: 2.4, 6.0, -89.54, 111.111.

  • To input a real number at the screen, use float(input())

A boolean variable always has the value True or False. Remember Python is case sensitive so the capital T or F really matters!

Operators

The following operators are used in expressions in Python:

Operator What it means Example
+ Add to 4 + 5
- Subtract 5 - 1
* Multiply 7 * 3
/ Divide 7 / 4
// Whole number division 20 // 3
% Remainder after whole number division 20 % 3
** To the power of 3 ** 4
== Equals 5 == 4
!= Not equals to 5 != 4
> Greater than 5 > 4
< Less than 5 < 4
>= Greater than or equal to 5 >= 5
<= Less than or equal to 4 <= 4
& Logical AND True & False