fn main() {
let guess:u32 = "42".parse().expect("NaN");
println!("guess is {}", guess); //42
}
中文 | Number literals | Example |
---|---|---|
普通常数 | Decimal | 98_222 |
16进制 | Hex | 0xff |
8进制 | Octal | 0o77 |
2进制 | Binary | 0b1111_0000 |
字节类型 | Byte(u8 only) | b’A’ |
fn main() {
let x = 2.0; //f64
let y:f32 = 1.5; //f32
}
fn main() {
let sum = 5 + 10; //i32
let difference = 1.5 - 1.1; //f64
let produce = 5 * 7; //i32
let quotient = 56.7 / 32.2; //f64
let reminder = 5 % 3; //i32
}
true
和 false
fn main() {
let t = true; //bool
let f:bool = false; //bool
}
U+0000
到 U+D7FF
U+E000
到 U+10FFFF
fn main() {
let x = 'Z';
let y:char = '★'; //char
let z = '🌚'; //char
}