Data types

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: Whole numbers

Integers in Jinja are whole numbers without decimal points. Examples include 1, 2, and 3.

{{- 1 -}}

Floats: Decimal numbers

Floats encompass numbers with decimal points, such as 1.1, 2.2, and 3.14.

{{- 1.1 -}}

Strings: Textual data

Strings represent words or sentences enclosed in quotes, like "Hello World".

{{- "hello world" -}}

Lists: Ordered collections

Lists are ordered collections of data, allowing a mix of different types within the same list.

{{- ["hello", "world", 1, 2, 3] -}}

Tuples: Immutable pairs

Tuples consist of two or more linked values, enclosed in parentheses and separated by commas. Tuples cannot be changed after creation.

Dictionaries: Key-value pairs

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.

Sets: Unique values

Sets are collections of unique values, eliminating duplicates. Converting a list into a set removes duplicate items.

Booleans: True or false

Booleans represent truth values and can be either true or false.

NoneType: Null values

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?