0% found this document useful (0 votes)
18 views1 page

Essential Python String Functions

Uploaded by

simpat00000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

Essential Python String Functions

Uploaded by

simpat00000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Common Python String Functions Usable in PySpark:

1. upper() - Converts string to uppercase


2. lower() - Converts string to lowercase
3. title() - Converts first letter of each word to uppercase
4. capitalize() - Converts first character to uppercase, rest lowercase
5. strip() - Removes leading/trailing whitespace
6. lstrip() - Removes leading whitespace
7. rstrip() - Removes trailing whitespace
8. replace(old, new) - Replaces all occurrences of old with new
9. split(sep) - Splits string into a list
10. join(iterable) - Joins elements of iterable with the string as separator
11. find(sub) - Returns first index of substring, -1 if not found
12. rfind(sub) - Returns last index of substring, -1 if not found
13. index(sub) - Like find(), but raises ValueError if not found
14. rindex(sub) - Like rfind(), but raises ValueError if not found
15. startswith(prefix) - Checks if string starts with prefix
16. endswith(suffix) - Checks if string ends with suffix
17. isalpha() - Checks if all characters are alphabetic
18. isdigit() - Checks if all characters are digits
19. isalnum() - Checks if all characters are alphanumeric
20. isspace() - Checks if all characters are whitespace
21. zfill(width) - Pads string on left with zeros to reach width
22. center(width, fillchar) - Centers string, padding with fillchar
23. ljust(width, fillchar) - Left justifies string
24. rjust(width, fillchar) - Right justifies string
25. count(sub) - Counts non-overlapping occurrences of substring
26. format(*args, **kwargs) - Formats string using placeholders
27. casefold() - Lowercases string more aggressively (for caseless comparisons)
28. swapcase() - Swaps uppercase to lowercase and vice versa
29. encode(encoding) - Encodes string to bytes
30. expandtabs(tabsize) - Replaces tabs with spaces

You might also like