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
- RegexIn regex, * repeats the previous item zero or more times, so ab*c matches ac, abc and abbc. To match a real asterisk, escape it as \* or use [*].
- PythonIn Python, * multiplies and ** raises to a power. In a def, *args and **kwargs collect extra arguments; in a call or a literal, * and ** unpack them.
- JavaScriptIn JavaScript, * multiplies, ** raises to a power, function* declares a generator and yield* delegates to another iterable. Spread and rest use ..., not *.
- C pointersIn C, * in a declaration makes a pointer (int *p) and * in an expression reads or writes what it points to (*p = 5). int* p and int *p mean the same.
- SQLIn SQL, SELECT * returns every column and COUNT(*) counts every row, NULLs included, while COUNT(column) skips NULLs. Plus when to avoid SELECT *.
- MarkdownIn Markdown, *text* is italic, **text** is bold and ***text*** is both. A * and a space at the start of a line makes a bullet. Type \* for a literal *.
- Bash globIn Bash and Zsh, * matches any characters in a file name, so *.txt expands to every .txt file. It skips hidden files. Quote it ('*') to pass it literally.
- CSS universal selectorIn CSS, * is the universal selector: it matches every element. Its most common use is the box-sizing reset. It has zero specificity, so other rules win.
- Google Search wildcardIn Google, * stands in for missing words inside a quoted phrase, like "a * in time saves nine". It doesn't complete partial words such as photo*.
- Excel wildcardsIn Excel, * matches any number of characters and ? matches one, but only in criteria and lookups like COUNTIF and XLOOKUP. FILTER and = ignore them.
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.