Number type

2 snippets across 2 stacks - Python, TypeScript

Also written as number types

PYPython

Integers & Floats

PY · Numbers
Syntax
x = 42      # int
y = 3.14    # float
Example
count = 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.

TSTypeScript

string, number, boolean

TS · Basic Types
Syntax
let varName: string = value;
let varName: number = value;
let varName: boolean = value;
Example
let 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.