Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Read environment variable

Rust

#![allow(unused)]
fn main() {
if let Ok(value) = std::env::var("MY_ENV_VAR") {
    println!("MY_ENV_VAR={value}")
}
}

Python

import os

if os.environ.get("MY_ENV_VAR"):
    value = os.environ["MY_ENV_VAR"]
    print(f"MY_ENV_VAR={value}")