End[]
returns the present context, and reverts to the previous one.
End
End[]
returns the present context, and reverts to the previous one.
Details
- Every call to End must be balanced by an earlier call to Begin.
- End[] resets the values of $Context and $ContextAliases.
- End[] returns the present context name as a string of the form "context`".
- End[] does not modify $ContextPath.
Examples
open all close allBasic Examples (1)
Define a function f in the MyContext` Context:
originalcontext = Context[]Begin["MyContext`"]f[x_] := x ^ 2 + 1End[]The context is now what it was before Begin was used:
Context[] === originalcontextProperties & Relations (3)
Begin["cont`"] sets $Context to "cont`":
$Context = "Global`";
Begin["Example`"]
$ContextEnd restores $Context to its value before the matching Begin:
End[];
$ContextUnlike BeginPackage, Begin does not modify $ContextPath:
$ContextPath = {"Global`", "System`"};
Begin["Example`"];
$ContextPathSimilarly, End does not modify it, either:
End[];
$ContextPathBegin does not alter the value of $ContextAliases:
$ContextAliases = <|"c`" -> "Context`"|>;
Begin["Example`"];
$ContextAliasesEnd restores $ContextAliases to its value before the matching Begin:
$ContextAliases["e`"] = "Experimental`";
End[];
$ContextAliasesTech Notes
Related Guides
Related Workflows
- Handle Shadowing of Symbol Names
History
Introduced in 1988 (1.0) | Updated in 2021 (13.0)
Text
Wolfram Research (1988), End, Wolfram Language function, https://reference.wolfram.com/language/ref/End.html (updated 2021).
CMS
Wolfram Language. 1988. "End." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/End.html.
APA
Wolfram Language. (1988). End. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/End.html
BibTeX
@misc{reference.wolfram_2026_end, author="Wolfram Research", title="{End}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/End.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_end, organization={Wolfram Research}, title={End}, year={2021}, url={https://reference.wolfram.com/language/ref/End.html}, note=[Accessed: 13-June-2026]}