What Is a String in Python?

A string in Python is a value used to store text.

Beginners use strings all the time. A string can hold:

  • A word
  • A sentence
  • A number written as text
  • Even empty text like ""

Python knows something is a string when it is written inside quotes. This page defines the term clearly and shows where strings are commonly used.

name = "Alice"
message = 'Hello'

print(name)
print(message)

Output:

Alice
Hello

A string is text inside quotes. Python treats quoted text as a string value.

What a string is

A string is a value used to store text.

Strings can contain:

  • Words like "hello"
  • Names like 'Python'
  • Digits written as text like "123"
  • Empty text like ""

In Python, strings are written inside:

  • Single quotes: 'hello'
  • Double quotes: "hello"

These are all strings:

print("hello")
print('Python')
print("123")
print("")

How Python knows something is a string

Python checks for quotes around the value.

For example:

  • "42" is a string because it has quotes
  • 42 is an integer because it has no quotes
print(type("42"))
print(type(42))

Output:

<class 'str'>
<class 'int'>

Even when they look similar, strings and numbers are different types of values. If you want to inspect a value, the type() function is very useful.

Common places beginners use strings

Beginners often use strings for:

  • Names
  • Messages shown with print()
  • User input from input()
  • File names and file paths
  • Data read from files or APIs

Example:

name = "Maya"
filename = "notes.txt"

print("Hello, " + name)
print("Opening file:", filename)

In many beginner programs, most visible text is stored as strings.

What you can do with strings

Strings are not just for storing text. You can also work with them in useful ways.

Join text together with +

first = "Hello"
second = "World"

print(first + " " + second)

Output:

Hello World

Repeat text with *

print("ha" * 3)

Output:

hahaha

Get part of a string

You can access characters by position or take a slice of the string.

word = "Python"

print(word[0])
print(word[0:3])

Output:

P
Pyt

Change letter case

text = "PyThOn"

print(text.lower())
print(text.upper())

Output:

python
PYTHON

Split text or join parts together

text = "red,green,blue"
colors = text.split(",")

print(colors)
print("-".join(colors))

Output:

['red', 'green', 'blue']
red-green-blue

If you want to go deeper, see the beginner lesson on Python strings explained with basics and examples. You can also learn specific methods like split() and join().

Important beginner idea

Strings are text, not numbers.

This is one of the most important beginner ideas to understand.

For example:

print("5" + "3")
print(5 + 3)

Output:

53
8

Why?

  • "5" and "3" are strings, so Python joins them
  • 5 and 3 are numbers, so Python adds them

If you need math, convert the string first:

a = "5"
b = "3"

print(int(a) + int(b))

Output:

8

Use int() for whole numbers and float() for decimal numbers. If you need help with this, see how to convert a string to an integer in Python.

How this page is different from other string pages

This page defines the term string only.

It does not fully teach:

  • Every string method
  • Advanced formatting
  • All ways to create and modify strings

Use this page to understand the basic meaning of a string. Then move on to deeper pages for creating strings, changing them, splitting them, joining them, and formatting them.

Common mistakes

Beginners often run into these problems with strings:

  • Thinking quoted numbers are real numbers
  • Forgetting quotes around text
  • Mixing strings and integers with +
  • Expecting input() to return a number automatically

Example of a common mistake:

age = input("Enter your age: ")
print(age + 1)

This causes an error because input() returns a string, and Python cannot add a string and an integer directly.

A correct version is:

age = int(input("Enter your age: "))
print(age + 1)

When debugging string problems, these checks help a lot:

print(value)
print(type(value))
print(len(value))

Use them to answer simple questions:

  • What is the actual value?
  • What type is it?
  • How long is it?

FAQ

Is a string always text?

Yes. In Python, a string represents text data, even if the text contains digits like "123".

What is the difference between "5" and 5 in Python?

"5" is a string. 5 is an integer. The first is text, the second is a number.

Can a string be empty?

Yes. An empty string is written as "" or ''.

Do I have to use double quotes for strings?

No. You can use single quotes or double quotes. Both create strings.

Why does input() usually give me a string?

Because user input is read as text by default. Convert it if you need a number.

See also