Python
Strings and Numbers

0: Introduction
1: Python Strings
2: Python Numbers
3: Python Booleans
4: ▶︎ How to check if a variable is a string in Python
5: How to check if a variable is a number in Python
6: Python, how to check if a number is odd or even
7: Python, Accepting Input
8: Python Constants

[← back to the Valley]

Strings and Numbers: How to check if a variable is a string in Python

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:

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

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

name = "Roger"
isinstance(name, str) #True
◀︎ Python Booleans
▶︎ How to check if a variable is a number in Python

Lessons in this unit:

0: Introduction
1: Python Strings
2: Python Numbers
3: Python Booleans
4: ▶︎ How to check if a variable is a string in Python
5: How to check if a variable is a number in Python
6: Python, how to check if a number is odd or even
7: Python, Accepting Input
8: Python Constants

Join my AI Workshop!

The Web Development BOOTCAMP cohort starts in February 2026