---
title: "Begin"
language: "en"
type: "Symbol"
summary: "Begin[context`] resets the current context."
keywords: 
- hidden symbols
- private symbols
- begin context
- set context
canonical_url: "https://reference.wolfram.com/language/ref/Begin.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Namespace Management"
    link: "https://reference.wolfram.com/language/guide/NamespaceManagement.en.md"
  - 
    title: "Scoping Constructs"
    link: "https://reference.wolfram.com/language/guide/ScopingConstructs.en.md"
  - 
    title: "Package Bulletproofing"
    link: "https://reference.wolfram.com/language/guide/PackageBulletproofing.en.md"
  - 
    title: "Package Development"
    link: "https://reference.wolfram.com/language/guide/PackageDevelopment.en.md"
related_workflows: 
  - 
    title: "Handle Shadowing of Symbol Names"
    link: "https://reference.wolfram.com/language/workflow/HandleShadowingOfSymbolNames.en.md"
related_functions: 
  - 
    title: "End"
    link: "https://reference.wolfram.com/language/ref/End.en.md"
  - 
    title: "BeginPackage"
    link: "https://reference.wolfram.com/language/ref/BeginPackage.en.md"
  - 
    title: "EndPackage"
    link: "https://reference.wolfram.com/language/ref/EndPackage.en.md"
  - 
    title: "$ContextPath"
    link: "https://reference.wolfram.com/language/ref/$ContextPath.en.md"
  - 
    title: "Context"
    link: "https://reference.wolfram.com/language/ref/Context.en.md"
  - 
    title: "$ContextAliases"
    link: "https://reference.wolfram.com/language/ref/$ContextAliases.en.md"
  - 
    title: "CellContext"
    link: "https://reference.wolfram.com/language/ref/CellContext.en.md"
related_tutorials: 
  - 
    title: "Wolfram Language Packages"
    link: "https://reference.wolfram.com/language/tutorial/ModularityAndTheNamingOfThings.en.md#3780"
  - 
    title: "Setting Up Wolfram Language Packages"
    link: "https://reference.wolfram.com/language/tutorial/ModularityAndTheNamingOfThings.en.md#5934"
---
# Begin

Begin["context`"]
resets the current context.

## Details

* ``Begin`` resets the value of ``\$Context``.

* The interpretation of symbol names depends on context. ``Begin`` thus affects the parsing of input expressions.

---

## Examples (5)

### Basic Examples (1)

Define a function ``f`` in the ``MyContext``` ``Context`` :

```wl
In[1]:= Begin["MyContext`"]

Out[1]= "MyContext`"

In[2]:= f[x_] := x ^ 2 + 1
```

Restore the context:

```wl
In[3]:= End[]

Out[3]= "MyContext`"
```

``f`` will generally be hidden in the restored context:

```wl
In[4]:= ??f
```

Information::notfound: Symbol f not found.

The definitions are all in ``MyContext`f`` :

```wl
In[5]:= ??MyContext`f

MyContext`f

MyContext`f[MyContext`x_] := MyContext`x^2 + 1
```

The function can be called using its fully qualified name:

```wl
In[6]:= MyContext`f[a + b]

Out[6]= 1 + (a + b)^2
```

### Applications (1)

Make symbols used for package function definitions private, reducing the possibility for conflict:

```wl
In[1]:= BeginPackage["MyPackage`"]

Out[1]= "MyPackage`"
```

Any use of the symbol ``f`` in the package context ensures that ``f`` is created in that context:

```wl
In[2]:= f::usage = "f[x] gives x^2 + 1";
```

When the context given to ``Begin`` starts with ````` it extends from the current context:

```wl
In[3]:= Begin["`Private`"]

Out[3]= "MyPackage`Private`"

In[4]:= f[x_] := x ^ 2 + 1;

In[5]:= End[]

Out[5]= "MyPackage`Private`"

In[6]:= EndPackage[]
```

Since the symbol ``f`` is in the package context, the function works after ``EndPackage`` :

```wl
In[7]:= f[a + b]

Out[7]= 1 + (a + b)^2
```

You can see that the other variable uses the private context:

```wl
In[8]:= ??f

"f[x] gives x^2 + 1"

f[MyPackage`Private`x_] := MyPackage`Private`x^2 + 1
```

### Properties & Relations (3)

``Begin["cont`"]`` sets ``\$Context`` to ``"cont`"`` :

```wl
In[1]:=
$Context = "Global`";
Begin["Example`"]
$Context

Out[1]= "Example`"

Out[1]= "Example`"
```

``End`` restores ``\$Context`` to its value before the matching ``Begin`` :

```wl
In[2]:=
End[];
$Context

Out[2]= "Global`"
```

---

Unlike ``BeginPackage``, ``Begin`` does not modify ``\$ContextPath`` :

```wl
In[1]:=
$ContextPath = {"Global`", "System`"};
Begin["Example`"];
$ContextPath

Out[1]= {"Global`", "System`"}
```

Similarly, ``End`` does not modify it, either:

```wl
In[2]:=
End[];
$ContextPath

Out[2]= {"Global`", "System`"}
```

---

``Begin`` does not alter the value of ``\$ContextAliases`` :

```wl
In[1]:=
$ContextAliases = <|"c`" -> "Context`"|>;
Begin["Example`"];
$ContextAliases

Out[1]= <|"c`" -> "Context`"|>
```

``End`` restores ``\$ContextAliases`` to its value before the matching ``Begin`` :

```wl
In[2]:=
$ContextAliases["e`"] = "Experimental`";
End[];
$ContextAliases

Out[2]= <|"c`" -> "Context`"|>
```

## See Also

* [`End`](https://reference.wolfram.com/language/ref/End.en.md)
* [`BeginPackage`](https://reference.wolfram.com/language/ref/BeginPackage.en.md)
* [`EndPackage`](https://reference.wolfram.com/language/ref/EndPackage.en.md)
* [`\$ContextPath`](https://reference.wolfram.com/language/ref/$ContextPath.en.md)
* [`Context`](https://reference.wolfram.com/language/ref/Context.en.md)
* [`\$ContextAliases`](https://reference.wolfram.com/language/ref/$ContextAliases.en.md)
* [`CellContext`](https://reference.wolfram.com/language/ref/CellContext.en.md)

## Tech Notes

* [Wolfram Language Packages](https://reference.wolfram.com/language/tutorial/ModularityAndTheNamingOfThings.en.md#3780)
* [Setting Up Wolfram Language Packages](https://reference.wolfram.com/language/tutorial/ModularityAndTheNamingOfThings.en.md#5934)

## Related Guides

* [Namespace Management](https://reference.wolfram.com/language/guide/NamespaceManagement.en.md)
* [Scoping Constructs](https://reference.wolfram.com/language/guide/ScopingConstructs.en.md)
* [Package Bulletproofing](https://reference.wolfram.com/language/guide/PackageBulletproofing.en.md)
* [Package Development](https://reference.wolfram.com/language/guide/PackageDevelopment.en.md)

## Related Workflows

* [Handle Shadowing of Symbol Names](https://reference.wolfram.com/language/workflow/HandleShadowingOfSymbolNames.en.md)

## History

* Introduced in 1988 (1.0)