The one-line declaration that sets fname to "john", lname to "doe", and age to 46 has no universal form. The keyword doesn't name a language, so the literal answer depends on where you run it: in Python it's fname, lname, age = "john", "doe", 46; in JavaScript it's let fname = "john", lname = "doe", age = 46;; in C it's char fname[] = "john", lname[] = "doe"; int age = 46;. Each puts three names and three values on a single line, and each fails differently β a Python syntax error, a JavaScript hoisting quirk, a C buffer limit. Picking the right one is the first thing to settle.
Declaring Three Named Values on One Line in Python
Python's tuple unpacking gives you the cleanest form: fname, lname, age = "john", "doe", 46. The left-hand side is a tuple of three targets, the right-hand side a tuple of three values, and Python assigns them positionally from left to right. All three names exist as ordinary local variables after that single statement, with fname bound to the string "john", lname to "doe", and age to the integer 46. No boilerplate, no type declarations, no semicolons.
The most common mistake is writing fname, lname, age = "john" with only one value on the right. Python raises ValueError: not enough values to unpack (expected 3, got 1) and none of the three names gets assigned. You'll see the same error, with "too many values" in the message, if you supply four values for three targets. The error is the feature: it catches a mismatch the moment the line runs instead of letting a half-populated variable drift into later logic.
A second trap is name shadowing. Because lname and fname are plain names, assigning them inside a function creates local variables that vanish on return; assigning them at module level creates globals. If you later write lname = lname.strip(), the reassignment is legal and silent, which means a typo like lname = Iname.strip() will create a new variable instead of failing. Use a linter β pylint reports undefined names β before you trust the block.
One useful extension: after the one-line declaration, add type hints on a separate line, fname: str = "john"; lname: str = "doe"; age: int = 46, if your team enforces static typing. Python 3.6 and later accept variable annotations, and the annotated form still fits on one line with semicolons. Keep the unannotated form for scripts and the annotated form for code that a type checker like mypy will inspect.
The JavaScript One-Line Form and Its Variable-Keyword Trap
In JavaScript, let fname = "john", lname = "doe", age = 46; declares three block-scoped variables on one line separated by commas β the keyword appears once, not three times. Writing let fname = "john", let lname = "doe" throws a SyntaxError because let can only introduce the list once. Use const if none of the three values will be reassigned, and var only when you genuinely need function-scoped hoisting.
The trap with var is hoisting. In var fname = "john", lname = "doe", age = 46; all three declarations are hoisted to the top of the enclosing function and initialized as undefined until the line runs. If code above the line reads lname, it sees undefined rather than a ReferenceError. With let or const, reading before the line throws ReferenceError: Cannot access 'lname' before initialization, which is the behavior you want in almost every case.
Semicolon-free style (common with StandardJS) lets you write the same line without the trailing semicolon, and it works because the next line's token can't be confused for a continuation. Don't rely on that when the next line starts with ( or [ β automatic semicolon insertion can join the statements in ways that surprise you. Put a semicolon at the end of the declaration block and stop worrying about it.
String quotes in JavaScript are interchangeable between single and double, so 'john' and "john" produce the same value. Template literals, backticks, are for interpolation and should not be used for plain literals. If you paste the declaration into a module and export it, add export in front β export const fname = "john", lname = "doe", age = 46; β and the single-line form survives intact.
In C and C++, One Line Hides Two Different Declarators
C forces you to split the declaration across two kinds of type. A working one-liner is char fname[] = "john", lname[] = "doe"; int age = 46; β the comma separates two array declarators of the same base type, and a semicolon then introduces the integer. You cannot legally declare both char[] and int under one type specifier without a semicolon in between, which is why the canonical C answer is two statements, not one. char *fname = "john", *lname = "doe"; int age = 46; also compiles but points at string literals; modifying them later is undefined behavior.
The dangerous mistake is char fname[] = "john", lname[] = "doe" with a later call to strcat. A 5-byte array holding 'j', 'o', 'h', 'n', and the null terminator has no room for extra characters, so the concatenation writes past the buffer and corrupts adjacent memory. The declared array size is a hard budget. If you intend to append anything, size it explicitly: char fname = "john", lname = "doe";.
age declared as int binds to 46 at compile time and is a genuine integer, not a string. If you print it with printf("%s", age), you get undefined behavior; use %d on an int and %s on a char* or array. Compilers with -Wall -Wformat will catch the mismatch. If you need age as a string, convert with snprintf(buf, sizeof buf, "%d", age) rather than casting.
A shell tidbit sits close to the C form: in bash, fname=john lname=doe age=46; export fname lname age sets and exports three variables on one line, and echo "$fname $lname is $age" prints "john doe is 46". No spaces around the = in bash β fname = john is a command invocation followed by two arguments and fails, which is the opposite of the Python rule.
One Line, Four Very Different Memory Costs
The declarations look equivalent on screen but allocate differently, and a 46-year-old record stored a million times pays for the difference. In CPython 3.6 through 3.11, fname and lname are references to interned string constants, while age is a small-int object shared across the interpreter; the per-row cost is three pointers, not three strings. In JavaScript, the three bindings live in a block scope frame and the strings are immutable primitives, so the V8 engine can share them internally. In C, an array is inline bytes you wrote, while a pointer is an address you store.
The table below is one the top results rarely build β it isolates what the declaration itself costs, not what serializing the record costs later:
| Language | Bare one-liner | Statement brokered by | Type of age | Main allocation risk |
|---|---|---|---|---|
| Python 3.11 | fname, lname, age = "john", "doe", 46 | Tuple unpacking | int | Interning negates savings; typos create silent names |
| JavaScript (ES2020+) | let fname = "john", lname = "doe", age = 46; | Comma-separated binding list | Number | var hoisting hides undefined reads |
| C (C11) | char fname[] = "john", lname[] = "doe"; int age = 46; | Array declarators + semicolon | int | Fixed-size buffers overflow on concatenation |
| Rust (2021) | let (fname, lname, age) = ("john", "doe", 46); | Tuple destructuring | i32 (inferred) | Ownership borrowing blocks accidental aliasing |
The numbers in the last column's source are in the language specs: Python's tuple unpacking applies the UNPACK_SEQUENCE opcode, the ECMAScript 2020 grammar defines the comma-separated VariableDeclarationList, and the C11 standard specifies array initializers of the declared type. Each language gives you one line, but only Python and Rust get you all three names under one binding form with a single separator; C needs a semicolon because its grammar permits one type per declaration statement.
Values Checked Before the Statement Runs: Python's Unpacking Behavior
Python's unpacking evaluates the right-hand tuple first, then walks the targets left to right. That order matters if you build values inside the tuple: fname, lname, age = get_first(), get_last(), get_age() calls get_first() first and get_age() last. If get_age() raises, fname and lname may already be bound while age is not, so a surrounding try block is the only way to know whether all three names exist. Wrap the declaration in a try and inspect names with locals() if you need to confirm.
String types are excused from the string-check: age = 46 binds an integer, and doing age + " years" later throws TypeError: unsupported operand type(s) for +: 'int' and 'str'. The one-line declaration does not coerce. If your downstream code wants a string, write age = 46 and format at the point of use with an f-string: f"{fname} {lname} is {age}" in Python 3.6 and later. This keeps the integer honest for arithmetic while printing correctly.
Rust's destructuring is the strict variant: let (fname, lname, age) = ("john", "doe", 46); fails at compile time if you later try to mutate fname without mut, and the compiler tells you the borrow checker's reason. Type inference settles on &str for both names and i32 for age β the same default integer type Rust uses for unsuffixed literals. If you need a 64-bit age, write age: i64 = 46 inside the pattern.
Swift brings a similar one-liner with a different flavor: let (fname, lname, age) = ("john", "doe", 46) in a struck tuple binding works, and the compiler raises Cannot assign to value: 'fname' is a 'let' constant if you reassign without declaring var. This is the kind of stale-value bug the one-line form can hide: you declare once, then later use a stale fname because the reassignment wasn't reachable on every branch.
The Failure Cases Where the One-Liner Breaks Quietly
Three edge scenarios separate the careful answer from the copy-paste answer. First, Python's age = 46 is fine for arithmetic but breaks when a data source sends "46" as a string and your if age > 18 comparison raises TypeError. Coerce at the boundary: age = int(raw_age). Second, declaring let age = 46; and later writing age = "46" in JavaScript does not fail β the language silently changes the variable's type, and a subsequent age + 2 concatenates instead of adding. Use const when values are fixed to get a TypeError from the assignment. Third, the C one-liner's comma does not do what you think when one of the names is a pointer and the other an array β char *fname = "john", lname[] = "doe" is a compile error in the same declaration because the two declarators disagree.
The most expensive failure is the one that doesn't fail at all: JavaScript's var version. If you paste var fname = "john", lname = "doe", age = 46; inside a function and refer to lname inside a nested if that runs before it, you get undefined rather than an error. In Strict Mode ('use strict'; at the top of the file), an undeclared name throws; var'd names do not, because they were declared, just not yet initialized. Our recommendation: use const for fname and lname, let for age only if it changes, and ban var in the file with an ESLint rule.
Python's assert age == 46 right after the declaration is a cheap guard: it confirms the literal value you expected arrived instead of a string. In a test suite, keep it; in production code, remove it so python -O does not change behavior. This is the kind of 10-second check that earns its place in a data-cleaning script where fname might come from a column read as "john " with a trailing space.
Run It Before Touching Your Real Data
Whether you're in Python, JavaScript, C, or shell, run the declaration once against a tiny fixture and print the values before trusting it. A three-line setup β the declaration, print(fname, lname, age), and print(type(age)) β exposes string-vs-int bugs in under a second. In JavaScript, replace those prints with console.log(typeof age) and console.log(fname, lname, age). The point is to make the type of age visible, because that's where the four languages disagree the most.
Naming is the second deliverable. fname and lname are fine tokens, but check the naming convention your project follows: PEP 8 prefers first_name and last_name, Google's JavaScript style guide requires camelCase, and the C coding standard for the Linux kernel uses snake_case. Renaming later is a find-and-replace, but if the names are exported from a module or spread into a data payload, the rename is breaking. Decide the names when you write the declaration line, not after.
Error messages name the fix. Python's ValueError: not enough values to unpack tells you the right-hand side has too few items. JavaScript's SyntaxError: Identifier 'lname' has already been declared tells you the keyword was repeated or the name collides. C's warning: incompatible pointer types from GCC tells you the declarator and the initializer disagree. Paste the exact error text into a search or read the one line of the message slowly; in our experience, all four of these are self-explanatory if you don't skip the line numbering.
A final check: rerun the line on an empty environment. In Python, del fname, lname, age then rerun the declaration proves the line is self-contained. In the browser console, the same with fname = undefined isn't enough because the binding survives; open a fresh console tab instead. If the declaration fails in a fresh environment, the values were coming from somewhere else β a module-level import, a previously executed line, or a leaked global β and the one-liner is not as self-contained as it looks.
Worked Comparison: How Three Names Become One Record
If the goal is a record, the one-line declaration is step one, and the join step is where people lose time. In Python, record = {"fname": fname, "lname": lname, "age": age} packs the three names into a dictionary with the same spelled keys; if you want a different key set, rename at the dict literal, not at the declaration. In JavaScript, const record = { fname, lname, age }; uses shorthand properties, a syntax that arrived with ES2015 and shortens the object literal to three bare names, and happily accepts the same identifiers.
In C, there is no built-in dictionary, so the equivalent is a struct: struct Person { char fname; char lname; int age; }; then struct Person p = {"john", "doe", 46}; initializes the fields in declaration order. If you change the field order in the struct, the string initializer still compiles but binds the wrong values β a silent bug the compiler cannot catch. Keep declaration order stable once data is flowing through it, or use designated initializers (.fname = "john", .age = 46) to make the order explicit. That designated syntax is C99 and later, and it is one of the few additions that makes the one-line form safer.
Cross-language migration is a recurring version of this task. Move age from Python to JavaScript and it becomes a Number; move it back and it becomes an int again under the hood, so a print(age) round trip prints 46 on both ends. Move the same record through JSON and age stays a number while the two names stay strings, which is exactly the type split the one-line declaration created β JSON preserves it because the JSON grammar distinguishes numbers from strings. This is the practical reason the type of age matters: any pipeline that serializes the record will preserve the 46 as a number and "john" as text, and the receiving language's parser decides whether age comes back as an int or a float.
If you want to test the pipeline, keep a canonical fixture. In Python, assert (fname, lname, age) == ("john", "doe", 46) after the declaration pins the values; in JavaScript, expect([fname, lname, age]).toEqual(["john", "doe", 46]); in Jest and assert.deepStrictEqual in Node do the same. One declaration line plus one assertion line covers the common failure of string-vs-int mixing that shows up when the same data crosses a network boundary. That assertion also catches the "46"-from-a-string bug before it corrupts an aggregate.
FAQ
Does the order of the variables matter in the one-line declaration?
Yes β in every language with positional assignment, the first value on the right binds to the first name on the left. In Python, fname, lname, age = "john", "doe", 46 binds "john" to fname; swap the left-hand names only and lname receives "john". Tell-tale symptom: a record whose last name is the first name, because someone edited the targets without editing the values.
Can I declare age as a string instead of an integer in Python?
You can, age = "46", and it's often a mistake. Arithmetic like age + 1 raises TypeError: can only concatenate str (not "int") to str, and comparisons to integers fail. If age arrives from a CSV or JSON field, cast it with int(age) at the boundary and keep the variable an integer; that keeps every later arithmetic check working.
Why does my Python line throw ValueError: not enough values to unpack?
Because the number of targets on the left of = exceeds the number of items on the right. For example, fname, lname, age = "john", "doe" has three names and two values. Change to fname, lname = "john", "doe" for two targets, or supply the third value. The message names how many values were expected and how many it got.
Is let or const better for the JavaScript version?
Use const for fname and lname if you won't reassign them β const fname = "john", lname = "doe"; is valid and rejects a later fname = "jane" with TypeError: Assignment to constant variable. Use let for age only if it changes. Both are equally fast in modern engines; the choice is about preventing bugs, not performance.
Can I do the same three-way declaration in C# or Java?
C# allows var fname = "john"; var lname = "doe"; var age = 46; on separate lines and string fname = "john", lname = "doe"; int age = 46; for the type-explicit pair; Java has no comma-separated declaration that mixes String and int, so the canonical answer is three lines. Neither language provides one single-line tuple unpacking form out of the box before their newer tuple support.
Does the one-line declaration work inside a function as well as at module level?
Yes, with a scope caveat. In Python, a function-level unpacking creates locals; the same code at module level creates globals. In JavaScript, a let inside a function is local to that function's block. If you need the three names available elsewhere, return them as a tuple or object instead of depending on module-level state, because the JavaScript version's const inside a function is not visible outside it.
What does age = 46 store in JavaScript β a number or a float?
A JavaScript Number, which is a double-precision float under the hood; there is no separate int type. 46 is exact because small integers are stored precisely, but 0.1 + 0.2 is not 0.3 for the same reason. If you need integer arithmetic with a different width, use BigInt (const age = 46n) but note that you cannot mix BigInt and Number in arithmetic.
Can I put the declaration inside a single line of SQL instead?
You can't create three variables with that syntax in SQL, but the analogous one-line construct is a single INSERT": INSERT INTO people (fname, lname, age) VALUES ('john', 'doe', 46); β one statement, three named columns, three values. The 46` is an integer literal in every major database engine, so the age stays numeric through storage and retrieval.