Jinja data types
Last updated
Was this helpful?
Understanding data types is fundamental for effective programming in Jinja templating. This article provides a comprehensive overview of the main data types in Jinja, exploring integers, floats, strings, lists, tuples, dictionaries, sets, booleans, and NoneType.
A data type is a classification that specifies the type of value a variable can hold, which determines the operations that can be performed on it and how the data is stored. Understanding data types is fundamental for effective programming in Jinja templating.
Integers in Jinja are whole numbers without decimal points. Examples include 1, 2, and 3.
{{- 1 -}}Floats encompass numbers with decimal points, such as 1.1, 2.2, and 3.14.
{{- 1.1 -}}Strings represent words or sentences enclosed in quotes, like "Hello World".
{{- "hello world" -}}Lists are ordered collections of data, allowing a mix of different types within the same list.
{{- ["hello", "world", 1, 2, 3] -}}Learn how to work with Jinja lists here, and how to combine Jinja lists here.
Tuples consist of two or more linked values, enclosed in parentheses and separated by commas. Tuples cannot be changed after creation.
Dictionaries store data in key-value pairs, similar to JSON. To retrieve a value from your dictionary, you use the key that you stored the value with. They can be modified and appended to after creation.
Learn about dictionary unpacking here.
Sets are collections of unique values, eliminating duplicates. Converting a list into a set removes duplicate items.
Booleans represent truth values and can be either true or false.
NoneType represents null or None values, indicating the absence of a value. To check for NoneType, the keyword none is used.
Last updated
Was this helpful?
Was this helpful?
{{- (1, 0) -}}
or
{% set myPair = ("dog", "cat") %}{{-
{
"name": "rewsty",
"age": 12908290382,
"favorite_colors": ["red", "blue", "black", "teal"],
}
-}}{{- {1, 2, 3} -}}{{- true -}}{{- none -}}