Name

string

Examples
str1 = 'CCCP'
str2 = "CCCP"
print(str1)        # Prints 'CCCP'
print(str2)        # Prints 'CCCP'
# Use a backslash to include quotes inside of a string.
single_quote = 'This one has \'quotes\''
double_quote = "This one also has \"quotes\""
print(single_quote)
print(double_quote)
# Use triple quotes to include text that spans multiple lines.
wcwilliams = """And you may be sure
not one leaf will lift itself
from the ground
and become fast to a twig again."""
print(wcwilliams)
Description A string is a sequence of characters. Python's built-in string class includes methods for searching strings, transforming strings, and checking to see if a string has particular characteristics. Strings are defined inside either double quotes ("ABC") or single quotes ('ABC').

Because strings are defined between quotation marks, to include such marks within the string itself you must use the \ (backslash) character. (See the second example above.) This is known as an escape sequence. Other escape sequences include \t for the tab character and \n for new line. Because backslash is the escape character, to include a single backslash within a string, you must use two consecutive backslashes, as in: \\

Normally, strings in your program must be written entirely on one line. If you want to include a chunk of text in your program that spans multiple lines, you can use triple quotes (either """ or '''). (See the third example above.)

There are more string methods than those linked from this page. Additional documentation is located online in the official Python documentation.
Syntax
	'str'
	"str"
	"""
	str
	"""
Parameters
strany string of characters
Methods
find()Find a substring and return its index
join()Join a list of strings, using a string as a separator
lower()Return a copy of a string with its characters converted to lowercase
replace()Return a copy of a string, replacing a given substring with another string
split()Break up a string into a list of parts, using a specified delimiter
startswith()Check to see if a string begins with a particular substring
strip()Return a copy of a string, with whitespace at the beginning and end removed
upper()Return a copy of a string with its characters converted to uppercase
Related String Formatting
.find()
.strip()
.join()
.split()
.replace()

Updated on Mon Sep 21 15:53:25 2020.

If you see any errors or have comments, please let us know.