Also written as number types
Integers & Floats
PY · Numbers Syntaxx = 42
y = 3.14
Examplecount = 1_000_000
ratio = 0.618
print(type(count), type(ratio))
print(count + ratio)
Output<class 'int'> <class 'float'>
1000000.618
Note Underscores in numeric literals are ignored and serve as visual separators. Python ints have unlimited precision.
string, number, boolean
TS · Basic Types Syntaxlet varName: string = value;
let varName: number = value;
let varName: boolean = value;
Examplelet username: string = "alice";
let price: number = 29.99;
let isActive: boolean = true;
Output// All three are primitive types inferred automatically when initialized
Note Use lowercase string, number, boolean. The uppercase versions (String, Number, Boolean) are wrapper objects and almost never what you want.
Frequently asked questions
- How does Python handle number type?
- This task is covered in 2 stacks on this page: Python, TypeScript. The "Integers & Floats" snippet in Python uses `x = 42 # int`.
- Which code does the Python example use?
- The "Integers & Floats" snippet uses `x = 42 # int`, from the Numbers section of the Python cheat sheet.
- Which stacks cover "number type" on this page?
- Python, TypeScript. Together they hold 2 copy-ready snippets for this task.
- Is there anything to watch out for?
- Yes. For "Integers & Floats": Underscores in numeric literals are ignored and serve as visual separators. Python ints have unlimited precision.