> ## Documentation Index
> Fetch the complete documentation index at: https://codegeninc-tawsif-change-additional-tools-to-tools.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Variable Assignments

Codegen's enables manipulation of variable assignments via the following classes:

* [AssignmentStatement](../api-reference/core/AssignmentStatement) - A statement containing one or more assignments
* [Assignment](../api-reference/core/Assignment) - A single assignment within an AssignmentStatement

### Simple Value Changes

Consider the following source code:

```typescript
const userId = 123;
const [userName, userAge] = ["Eve", 25];
```

In Codegen, you can access assignments with the [get\_local\_var\_assignment](../api-reference/core/CodeBlock#get-local-var-assignment) method.

You can then manipulate the assignment with the [set\_value](../api-reference/core/Assignment#set-value) method.

```python
id_assignment = file.code_block.get_local_var_assignment("userId")
id_assignment.set_value("456")

name_assignment = file.code_block.get_local_var_assignment("name")
name_assignment.rename("userName")
```

<Note>
  Assignments inherit both [HasName](/api-reference/core/HasName) and
  [HasValue](/api-reference/core/HasValue) behaviors. See [Inheritable
  Behaviors](/building-with-codegen/inheritable-behaviors) for more details.
</Note>

### Type Annotations

Similarly, you can set type annotations with the [set\_type\_annotation](../api-reference/core/Assignment#set-type-annotation) method.

For example, consider the following source code:

```typescript
let status;
const data = fetchData();
```

You can manipulate the assignments as follows:

```python
status_assignment = file.code_block.get_local_var_assignment("status")
status_assignment.set_type_annotation("Status")
status_assignment.set_value("Status.ACTIVE")

data_assignment = file.code_block.get_local_var_assignment("data")
data_assignment.set_type_annotation("ResponseData<T>")

# Result:
let status: Status = Status.ACTIVE;
const data: ResponseData<T> = fetchData();
```

## Tracking Usages and Dependencies

Like other symbols, Assignments support [usages](/api-reference/core/Assignment#usages) and [dependencies](/api-reference/core/Assignment#dependencies).

```python
assignment = file.code_block.get_local_var_assignment("userId")

# Get all usages of the assignment
usages = assignment.usages

# Get all dependencies of the assignment
dependencies = assignment.dependencies
```

<Tip>
  See [Dependencies and Usages](/building-with-codegen/dependencies-and-usages)
  for more details.
</Tip>
