# Acceptable Named Tuple Names?

**URL:** <https://discourse.julialang.org/t/acceptable-named-tuple-names/85489>\
**Category:** New to Julia\
**Tags:** question, namedtuple\
**Created:** [August 8, 2022, 3:36pm UTC](https://discourse.julialang.org/t/acceptable-named-tuple-names/85489 "2022-08-08T15:36:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Conwell](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim_conwell/32/38642_2.png) [@Tim\_Conwell](https://discourse.julialang.org/u/Tim_Conwell)\
**Post date:** [August 8, 2022, 3:36pm UTC](https://discourse.julialang.org/t/acceptable-named-tuple-names/85489/1 "2022-08-08T15:36:42Z")

</div>

I’m working on functions to create html tags and am hoping to create named tuples with names that might include a hyphen for certain attributes. Can named tuples have names with a space or hyphen? How do you declare the names in that case? I have a version using Dict that works but named tuples appear to be faster and are easier to type.

Hoping for something like this:

```julia
attrs = (class = "1", style = "test", required = 1, "custom-attr" = "ok")

```

---

<div class="post-metadata">

**Author:** ![danielmatz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielmatz/32/2285_2.png) [@danielmatz](https://discourse.julialang.org/u/danielmatz)\
**Post date:** [August 8, 2022, 3:42pm UTC](https://discourse.julialang.org/t/acceptable-named-tuple-names/85489/2 "2022-08-08T15:42:47Z")

</div>

This seems to work:

```julia
attrs = (class = "1", style = "test", required = 1, var"custom-attr" = "ok")

```

This uses the `@var_str` string macro to create a `Symbol` that would otherwise not be valid.

Update:  
I just learned that `@var_str` doesn’t really exist. The `var""` syntax looks like a string macro, but it is actually implemented directly by the parser, according to the doc string.

---

<div class="post-metadata">

**Author:** ![Tim\_Conwell](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim_conwell/32/38642_2.png) [@Tim\_Conwell](https://discourse.julialang.org/u/Tim_Conwell)\
**Post date:** [August 8, 2022, 3:56pm UTC](https://discourse.julialang.org/t/acceptable-named-tuple-names/85489/3 "2022-08-08T15:56:49Z")

</div>

Thanks. This might be a different question, but can you make a named tuple with only one item? Or is there a different data type that I’d have to use to handle this case?  
ex:

```julia
attrs = (class = "1")

```

---

<div class="post-metadata">

**Author:** ![danielmatz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielmatz/32/2285_2.png) [@danielmatz](https://discourse.julialang.org/u/danielmatz)\
**Post date:** [August 8, 2022, 4:08pm UTC](https://discourse.julialang.org/t/acceptable-named-tuple-names/85489/4 "2022-08-08T16:08:04Z")

</div>

Just like with a normal `Tuple`, you need a trailing comma in there when you only have a single element:

```julia
attrs = (class = "1",)

```

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [August 8, 2022, 5:23pm UTC](https://discourse.julialang.org/t/acceptable-named-tuple-names/85489/5 "2022-08-08T17:23:07Z")

</div>

You can also use an initial semi-colon to mark it as a `NamedTuple`:

```julia
julia> attrs = (; class = "1")
(class = "1",)

```
