'
), double quotes ("
), and triple quotes ('''
or """
) for defining strings.Examples:
+
operator.Example:
*
operator.Example:
0
).Example:
string[start:stop:step]
Examples:
len()
function.Example:
upper()
and lower()
Example:
strip()
, lstrip()
, and rstrip()
Example:
replace()
Example:
split()
Example:
join()
Example:
find()
and index()
find()
returns -1
if the substring is not found, while index()
raises an error.Example:
startswith()
and endswith()
Example:
isalpha()
, isdigit()
, isalnum()
Example:
f-strings
(Python 3.6+){}
.Example:
format()
Method{}
.Example:
%
Formatting (Older Style)%
as a placeholder for values.Example:
\n
: Newline\t
: Tab\\
: Backslash\"
: Double quote\'
: Single quoteExample:
Concatenation:
Slicing:
String Methods:
String Formatting:
f-strings
for string formatting (Python 3.6+).+
for concatenating many strings (use join()
instead for efficiency).