San Jose State University Department of Applied Data Science
**DATA 200 Computational Programming for Data Analytics**
Spring 2023 Instructor: Ron Mak
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 8.10 Characters and Character-Testing Methods"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### The string character-testing methods test all the characters of a string.\n",
"| Method | Returns `True` if ... |\n",
"| --- | --- |\n",
"| `isalnum()` | The string contains only **alphanmeric** (letters and digit) characters. |\n",
"| `isalpha()` | The string contains only **alphabetic** (letters) characters. |\n",
"| `isdecimal()` | The string contains only **decimal integer** characters. |\n",
"| `isdigit()` | The string contains only digits (`'0'`, `'1'`, `'2'`, ... `'9'`). |\n",
"| `isidentifier()` | The string represents a valid Python **identifier**. |\n",
"| `isnumeric()` | The string represents **numeric value** without a `+` or `-` sign or a decimal point. |\n",
"| `isspace()` | The string contains only **whitespace** characters. |\n",
"| `istitle()` | Only the first character of each word in the string is **upper case**. |\n",
"| `isupper()` | The string contains only **upper-case** characters. |\n",
"| `islower()` | The string contains only **lower-case** characters. |\n",
"| `isascii()` | The string contains only **ASCII** characters (those with `ord()` less than 128). |"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"'-27'.isdigit()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"'27'.isdigit()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"'A9876'.isalnum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"'123 Main Street'.isalnum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"'∑x'.isascii()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"##########################################################################\n",
"# (C) Copyright 2019 by Deitel & Associates, Inc. and #\n",
"# Pearson Education, Inc. All Rights Reserved. #\n",
"# #\n",
"# DISCLAIMER: The authors and publisher of this book have used their #\n",
"# best efforts in preparing the book. These efforts include the #\n",
"# development, research, and testing of the theories and programs #\n",
"# to determine their effectiveness. The authors and publisher make #\n",
"# no warranty of any kind, expressed or implied, with regard to these #\n",
"# programs or to the documentation contained in these books. The authors #\n",
"# and publisher shall not be liable in any event for incidental or #\n",
"# consequential damages in connection with, or arising out of, the #\n",
"# furnishing, performance, or use of these programs. #\n",
"##########################################################################\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Additional material (C) Copyright 2023 by Ronald Mak"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 4
}