Member-only story
Strings in Python [2]
3 min readDec 13, 2024
Hello,
Press enter or click to view image in full size![]()
41. Check if String Contains Only Digits
pythonCopy codeonly_digits = "12345".isdigit() # True42. Convert String to List of Words
pythonCopy codewords = "Hello world, Python is great!".split() # ['Hello', 'world,', 'Python', 'is', 'great!']43. Check if String is Printable
pythonCopy codeis_printable = "Hello\nWorld".isprintable() # False (contains non-printable newline character)44. Left-Justify a String
pythonCopy codeleft_justified = "Hello".ljust(10, "-") # 'Hello-----'45. Right-Justify a String
pythonCopy coderight_justified = "Hello".rjust(10, "-") # '-----Hello'46. Remove Characters from Both Ends
pythonCopy codestripped = "---Hello---".strip("-") # 'Hello'







