> For the complete documentation index, see [llms.txt](https://university-west.gitbook.io/programming-paradigms/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://university-west.gitbook.io/programming-paradigms/programming-fundamentals/datatypes/literals.md).

# Literals

In computer programming, a literal is a notation for representing a fixed value in source code. Literals directly express specific data types' values within the code, such as numbers, characters, strings, or boolean values. Unlike variables and constants, which are named entities used to store data values that can be retrieved and manipulated, literals are the values themselves as written in the code.

#### Types of Literals:

1. **Integer Literals:** Represent whole numbers without fractions, such as `42`, `-1`, `0`.
2. **Floating-Point Literals:** Represent real numbers, which can include fractional parts, written with a decimal point or in exponential notation, such as `3.14`, `-0.01`, `2.5e2`.
3. **Character Literals:** Represent single characters, typically enclosed in single quotes, such as `'a'`, `'1'`, `'@'`.
4. **String Literals:** Represent sequences of characters enclosed in double quotes (in most languages), such as `"Hello, world!"`.
5. **Boolean Literals:** Represent truth values, usually written as `true` and `false`.
6. **Null Literal:** Represents the absence of a value or a null reference, usually written as `null` in many languages (or `None` in Python, `nil` in some other languages).

#### Characteristics of Literals:

* **Immutability:** The value of a literal does not change; it is a fixed part of the code.
* **Direct Representation:** Literals represent values directly in the code. When the program runs, these literals are interpreted as the values they represent.
* **Type Inference:** In some languages, the type of a literal can be inferred from its notation. For example, `42` is clearly an integer, while `3.14` is a floating-point number.

#### Examples:

```python
# Integer literal
num = 10

# Floating-point literal
pi = 3.14159

# Character literal (in languages like C or Java)
char c = 'A';

# String literal
greeting = "Hello, world!"

# Boolean literal
is_valid = true

# Null literal
reference = null
```

#### Usage:

Literals are used throughout programming to initialize variables, pass arguments to functions, and specify conditions in control structures. They are foundational to expressing basic values and structures directly in code, making them an indispensable part of programming syntax.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://university-west.gitbook.io/programming-paradigms/programming-fundamentals/datatypes/literals.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
