The asterisk in code

In most programming languages, * means multiply. Beyond that it has three common jobs: "any number of" (regex, shell globs, search and spreadsheet wildcards), "everything" (SELECT *, the CSS * selector) and "unpack" or "point to" (Python's *args, C pointers). The table shows which one you're looking at.

What * means, language by language

Where What * does Example
Regular expressions Zero or more of the previous item ab*c matches ac, abc, abbbc
Python Multiplies; in a definition or call, collects or unpacks arguments def f(*args, **kwargs)
JavaScript Multiplies; ** is power; function* makes a generator 2 ** 10 is 1024
C and C++ Multiplies; in a declaration, "pointer to"; in an expression, "the value at" int *p = &x;
SQL Every column; COUNT(*) counts rows SELECT * FROM users;
Markdown Italic, bold or a bullet *italic*, **bold**
Bash, Zsh and other shells Any characters in a file name ls *.txt
CSS Every element * { box-sizing: border-box; }
Google Search A missing word in a quoted phrase "a * in time saves nine"
Excel and Google Sheets Any characters, in criteria and lookups =COUNTIF(A:A,"*north*")

Guides by language and tool

When pasted code fails because of the asterisk

Code only understands the plain keyboard asterisk, * (U+002A). Lookalikes sneak in when code is copied from a PDF, a slide deck or a word processor, or typed with a Japanese or Chinese input method switched on. They look right and fail in confusing ways:

>>> 2 ∗ 3
SyntaxError: invalid character '∗' (U+2217)
>>> 2 * 3
SyntaxError: invalid character '*' (U+FF0A)

The usual culprits are the asterisk operator ∗, which LaTeX PDFs produce for \ast, and the fullwidth asterisk * from East Asian keyboards. Retype the character with Shift + 8, or search the file for the code point in the error message.

Why one key has so many jobs

FORTRAN, released in 1957, used * for multiplication and ** for powers because punch-card character sets had no × or superscripts. Most languages since have kept that. The "zero or more" meaning comes from the mathematician Stephen Kleene, whose 1950s work on regular languages gave us the Kleene star. Unix shells borrowed a looser version of it for file names, and spreadsheets and search engines followed. Language designers needed a spare symbol, and the asterisk was already on every keyboard and doing nothing more important than footnotes.