---
title: "Structures"
url: https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures
language: python
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Structures

Programming language: Python. Other languages: [C++](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/php.md), [Ruby](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/swift.md).

## Struct Syntax

A structure groups one or more named fields, of any type, into a new type. For example:

```slice
module M
{
    struct TimeOfDay
    {
        short hour;         // 0 - 23
        short minute;       // 0 - 59
        short second;       // 0 - 59
    }
}
```

This definition introduces a new type named `TimeOfDay`. The name of a field must be unique within its structure.

A structure contains only fields: as elsewhere in Slice, type definitions cannot be nested, except for [modules](https://docs.zeroc.com/ice/3.8/slice/modules/python.md). Like every other type, you define a structure in a module.

## Language Mapping

A Slice structure maps to a Python dataclass with the same name. For each Slice field, the Python dataclass contains a corresponding field. For example, here is our Employee structure once more:

```slice
struct Employee
{
    long number;
    string firstName;
    string lastName;
}
```

The Python mapping generates the following definition for this structure:

```py
@dataclass(order=True, unsafe_hash=True)
class Employee:
    number: int = 0
    firstName: str = ""
    lastName: str = ""
```

All mapped fields have default values, such as `0` and the empty string (see [Fields](https://docs.zeroc.com/ice/3.8/slice/fields/python.md) for details).

For structures that are also [legal dictionary key types](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/python.md), the mapped dataclass is configured with `order=True` and `unsafe_hash=True`, as shown in our example above. The hashing is “unsafe” because the mapped dataclass is not frozen.

## See Also

- [Fields](https://docs.zeroc.com/ice/3.8/slice/fields/python.md)
- [Classes](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/python.md)
