0% found this document useful (0 votes)
4 views2 pages

Python String Functions

This document provides a comprehensive overview of Python string functions categorized into four sections: Measuring & Checking, Modifying & Transforming, Searching & Finding, and Splitting & Joining. Each section lists various functions along with their descriptions, such as checking character types, modifying case, searching for substrings, and formatting strings. It serves as a quick reference guide for string manipulation in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Python String Functions

This document provides a comprehensive overview of Python string functions categorized into four sections: Measuring & Checking, Modifying & Transforming, Searching & Finding, and Splitting & Joining. Each section lists various functions along with their descriptions, such as checking character types, modifying case, searching for substrings, and formatting strings. It serves as a quick reference guide for string manipulation in Python.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python String Functions

Measuring & Checking

len(s) Returns the length of the string

[Link]() Checks if all characters are alphabetic

[Link]() Checks if all characters are digits

[Link]() Checks if all are alphanumeric

[Link]() Checks for only whitespace

[Link]() Checks if all letters are lowercase

[Link]() Checks if all letters are uppercase

[Link](x) Checks if string starts with x

[Link](x) Checks if string ends with x

Modifying & Transforming

[Link]() Converts to lowercase

[Link]() Converts to uppercase

[Link]() Capitalizes first character

[Link]() Capitalizes first character of each word

[Link]() Swaps case of each character

[Link]() Removes leading/trailing whitespace

[Link]() Removes leading whitespace

[Link]() Removes trailing whitespace

[Link](a, b) Replaces all a with b

Searching & Finding

[Link](x) Returns first index of x, -1 if not found

[Link](x) Returns last index of x

[Link](x) Like find() but raises error if not found

[Link](x) Counts occurrences of x

Splitting & Joining

[Link]() Splits string by whitespace (default)

[Link](',') Splits by a specific separator


Python String Functions

[Link]() Splits from the right

[Link](x) Splits into 3 parts: before, x, after

[Link](list) Joins list into string with separator

Formatting

[Link](...) Formats using {} placeholders

f"...{var}..." f-string formatting (Python 3.6+)

[Link](width) Pads string on left with zeros

[Link](w) Centers in a field of width w

[Link](w) Left-justifies in width w

[Link](w) Right-justifies in width w

You might also like