# How to check if a variable is a string in Python

> Learn how to check if a variable is a string in Python using the type() function or isinstance(), comparing the value against the built-in str class.

Author: Flavio Copes | Published: 2021-03-01 | Canonical: https://flaviocopes.com/python-check-string/

You can check if a variable is a string using the `type()` function, passing the variable as an argument, and then comparing the result to the `str` class:

```python
name = "Roger"
type(name) == str #True
```

Or using `isinstance()`, passing 2 arguments: the variable, and the `str` class:

```python
name = "Roger"
isinstance(name, str) #True
```
