Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #249 Declare and assign multiple variables

Define variables a, b and c in a concise way.
Explain if they need to have the same type.

int a, b, c = b = a = 123;
Object a = 42, b = "Hello", c = 5.;
var (a, b, c) = (42, "hello", 5.0);
var a = 42, b = "Hello", c = 5.0;
{A, B, C} = {42, "hello", 5.0}.
integer :: a, b, c
a, b, c := 42, "hello", 5.0
(a, b, c) = (42, "hello", 5.0)
const [a, b, c] = [42, "hello", 5.0];
val (a, b, c) = listOf("A", "B", "C")
my ($a, $b, $c) = (1, '2', 'three');
a, b, c = 42, 'hello', 5.0
a, b, c = 'xyz'
a, b, *c = '1111011'
*a, b, c = '1111011'
from decimal import Decimal
a, b, c = Decimal(1.23).as_tuple()
a, b, c = 42, 'hello', 5.0
let (a, b, c) = (42, "hello", 5.0);

New implementation...
< >
programming-idioms.org