Let's get started learning about these methods by looking at ` isalnum()`, which returns True if all characters in the string are alphanumeric and there is at least one character,
The `isalpha()` string method will return True if all characters in the string are alphabetic and there is at least one character
The `isascii()` string method will return True if the string is empty or all characters in the string are ASCII.
Here's an example that shows what happens with ASCII and Unicode (emoji)
The `isdecimal()` will return True if all characters in the string are decimal characters and there is at least one character,
Here's an example:
The `isdigit()` string method in #Python will return True if all characters in the string are digits and there is at least one character, False otherwise.
Digits include decimal characters and digits that need special handling
You can test a string to see if it can be an identifier using `isidentifier()`
Basically, you are testing if the string could be used as a variable or function name.
For full details on what an identifier is in #Python, see the docs:
As you might expect, `islower()` tests to see if all the characters in a string are lowercase
The `isnumeric()` string method will return True if all characters in the string are numeric characters, and there is at least one character
The `isprintable()` string method in #Python is used to check if all the characters in a string are printable or not
The `isspace()` string method in #Python will return True if there are only whitespace characters in the string and there is at least one character
Here are a few examples:
The `istitle()` string method will "return True if the string is a titlecased string and there is at least one character, for example, uppercase characters may only follow uncased characters and lowercase characters only cased ones"
The `isupper()` string method in #Python will return Return True if all cased characters in the string are uppercase and there is at least one cased character
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
Want to create a copy of a #Python list? Use Python's `copy()` method!
Note: Watch out if your list contains lists of dictionaries. In those cases, you might be better off using copy.deepcopy()
But be careful! If your list contains a mutable object, like another list or a dictionary, you may encounter some unexpected behavior.
In the following example, you `copy()` the list. Then you modify the nested dictionary in the copy, but that also changes the original list!
You can fix this behavior by using Python's `copy` module. It provides a deepcopy() function that you can use which will make a deep copy of the ENTIRE list!