WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

Last [expr]

gives the last element in expr.

Last [expr,def]

gives the last element if there are any elements, or def otherwise.

Details
Details and Options Details and Options
Examples  
Basic Examples  
Generalizations & Extensions  
Properties & Relations  
Possible Issues  
See Also
Tech Notes
Related Guides
Related Links
History
Cite this Page

Last [expr]

gives the last element in expr.

Last [expr,def]

gives the last element if there are any elements, or def otherwise.

Details

  • Last [expr] is equivalent to expr[[-1]].
  • Last has attribute HoldRest . In Last [expr,def], def is evaluated only if it is to be returned.

Examples

open all close all

Basic Examples  (5)

Extract the last element of a list:

Extract the last row of a matrix:

Extract the last element of an association:

The head need not be List :

Return x if there are zero elements:

Generalizations & Extensions  (1)

Last works on SparseArray objects:

Properties & Relations  (1)

Last [expr] is equivalent to expr[[-1]]:

Possible Issues  (2)

The expression is evaluated before Last is applied:

Last always operates on the FullForm of expressions:

See Also

Part   First   Take   Most

Tech Notes

History

Introduced in 1988 (1.0) | Updated in 2014 (10.0) 2015 (10.3)

Wolfram Research (1988), Last, Wolfram Language function, https://reference.wolfram.com/language/ref/Last.html (updated 2015).

Text

Wolfram Research (1988), Last, Wolfram Language function, https://reference.wolfram.com/language/ref/Last.html (updated 2015).

CMS

Wolfram Language. 1988. "Last." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/Last.html.

APA

Wolfram Language. (1988). Last. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Last.html

BibTeX

@misc{reference.wolfram_2025_last, author="Wolfram Research", title="{Last}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/Last.html}", note=[Accessed: 04-January-2026]}

BibLaTeX

@online{reference.wolfram_2025_last, organization={Wolfram Research}, title={Last}, year={2015}, url={https://reference.wolfram.com/language/ref/Last.html}, note=[Accessed: 04-January-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /