Primitive Data Types

  • Integer: int
  • Floating Point: double or float
  • Boolean: boolean or bool
  • String: char/String or str

Java

int x = 5;
double y = 5.5;
boolean z = true;
String word = "Hello";
System.out.println(x + word) // what does this output?

Python

x: int = 5
y: float = 5.5
z: bool = True
word: str = "Hello"
print(x + word) # what does this output?

Java

int x = 5;
double y = 5.5;
boolean z = true;
String word = "Hello";
System.out.println(x + word) // "5Hello"

Python

x: int = 5
y: float = 5.5
z: bool = True
word: str = "Hello"
print(x + word) # what does this output?

Java

int x = 5;
double y = 5.5;
boolean z = true;
String word = "Hello";
System.out.println(x + word) // "5Hello"

Python

x: int = 5
y: float = 5.5
z: bool = True
word: str = "Hello"
print(x + word) # TypeError!
The data type determines how variables are treated.

Different data types
support different operations.

Custom Data Type - Enum

An enum is a list of named values.

Python
from enum import Enum

class Grade(Enum): A = 1 B = 2 C = 3 D = 4 F = 5
Java
public enum Grade {
    A,
    B,
    C,
    D,
    F;
}

Custom Data Type - Enum

An enum defines a new data type.

Java

Grade gradeA = Grade.A;
Grade gradeB = Grade.B;
student.setGrade(Grade.C);

Python

grade_a: Grade = Grade.A
grade_b: Grade = Grade.B
student.set_grade(Grade.C)
Classes define new data types composed of one or more other types.

This new data type is the state of the object built from the class.

Type Systems

  • Java - Strong, Static Typing
  • Python - Strong, Dynamic Typing

We are using Mypy to make Python act like a statically typed language.