String (Python)

A string in Python is text wrapped in single or double quotes. Strings are immutable, meaning their contents can't be changed once created.

Python

You can join strings with +, repeat them with *, and access individual characters by index. Useful methods include .upper(), .lower(), .strip(), .replace(), and .split().

Syntax

text = "hello"  or  text = 'hello'

Examples

Python

greeting = "hello"
print(greeting.upper())
print(greeting[0])

Output:

HELLO
h

Learn it in a lesson

See also

Back to the Dictionary