> 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/control-structures/selection-conditional/ternary.md).

# Ternary

#### Ternary Operator

The ternary operator or conditional operator, is a simplified method for performing a basic `if-else` statement in a single line of code. The syntax typically follows the pattern: `condition ? expression_if_true : expression_if_false`. This allows for more concise and readable code when you need to assign a value based on a condition.

**Python Example**

```python
# Using the ternary operator to assign a message based on age
age = 20
message = "Adult" if age >= 18 else "Minor"
print(message)
```

**C# Example**

```csharp
// Using the ternary operator to decide if a number is odd or even
int number = 5;
string result = (number % 2 == 0) ? "Even" : "Odd";
Console.WriteLine(result);
```


---

# 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/control-structures/selection-conditional/ternary.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.
