---
title: "in"
space: "Student Handbook"
url: "https://portal.cs17.org/student-handbook/python-manual/strings/in"
updated: "2026-10-05"
---

Checks whether a piece of text, or an item, is inside another.

## Synopsis

```python
part in text
item in list
item not in list
```

## Description

`in` is an operator, not a function. It gives `True` or `False`.

## Return value

A `bool`.

## Example

```python
print("ell" in "hello")
print("z" in "hello")
print("yes" in ["y", "yes"])
print(3 not in [1, 2])
```

It prints:

```text
True
False
True
True
```

## Common mistake

```python
answer = "no"
if answer == "y" or "yes":
    print("Agreed.")
```

It prints:

```text
Agreed.
```

Each side of `or` is checked on its own, and `"yes"` alone counts as true, so this always agrees. Write `if answer in ["y", "yes"]:`.

## See also

[str.startswith](/student-handbook/python-manual/strings/startswith), [str.lower](/student-handbook/python-manual/strings/lower)

[in in the Python documentation](https://docs.python.org/3/library/stdtypes.html#common-sequence-operations)
