int
double
or float
boolean
or bool
char/String
or str
int x = 5;
double y = 5.5;
boolean z = true;
String word = "Hello";
System.out.println(x + word) // what does this output?
x: int = 5
y: float = 5.5
z: bool = True
word: str = "Hello"
print(x + word) # what does this output?
int x = 5;
double y = 5.5;
boolean z = true;
String word = "Hello";
System.out.println(x + word) // "5Hello"
x: int = 5
y: float = 5.5
z: bool = True
word: str = "Hello"
print(x + word) # what does this output?
int x = 5;
double y = 5.5;
boolean z = true;
String word = "Hello";
System.out.println(x + word) // "5Hello"
x: int = 5
y: float = 5.5
z: bool = True
word: str = "Hello"
print(x + word) # TypeError!
An enum is a list of named values.
from enum import Enum
class Grade(Enum):
A = 1
B = 2
C = 3
D = 4
F = 5
public enum Grade {
A,
B,
C,
D,
F;
}
An enum defines a new data type.
Grade gradeA = Grade.A;
Grade gradeB = Grade.B;
student.setGrade(Grade.C);
grade_a: Grade = Grade.A
grade_b: Grade = Grade.B
student.set_grade(Grade.C)
We are using Mypy to make Python act like a statically typed language.