Skip to content

Commit 217a920

Browse files
authored
[Term Entry] Python Strings .isalnum() (Codecademy#3295)
* [Term Entry] Python Strings .isalnum() * fix: spelling * implement the suggestions * review edits * Update isalnum.md ---------
1 parent 7336fcb commit 217a920

File tree

1 file changed

+51
-0
lines changed
  • content/python/concepts/strings/terms/isalnum

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
Title: '.isalnum()'
3+
Description: 'Returns True if all the characters in a given string are alphanumeric.'
4+
Subjects:
5+
- 'Data Science'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Strings'
9+
- 'Methods'
10+
- 'Functions'
11+
CatalogContent:
12+
- 'learn-python-3'
13+
- 'paths/analyze-data-with-python'
14+
---
15+
16+
The **`.isalnum()`** string method takes in a string and returns `True` if all the characters are alphanumeric (`A-Z`, `a-z`, `0-9`). Otherwise, it returns `False` if the string contains any non-alphanumeric characters (e.g. `@ # $ % - *`).
17+
18+
## Syntax
19+
20+
```pseudo
21+
my_string.isalnum()
22+
```
23+
24+
This method does not have any parameters.
25+
26+
## Example
27+
28+
The examples below use `.isalnum()` to check if all the characters are alphanumeric:
29+
30+
```py
31+
my_string = "AlphaNumeric001"
32+
print(my_string.isalnum())
33+
```
34+
35+
The code above will result in the following output:
36+
37+
```shell
38+
True
39+
```
40+
41+
## Codebyte Example
42+
43+
The code below is runnable and uses the `.isalnum()` method:
44+
45+
```codebyte/python
46+
my_string_1 = "string2023"
47+
print(my_string_1.isalnum())
48+
49+
my_string_2 = "@lpha"
50+
print(my_string_2.isalnum())
51+
```

0 commit comments

Comments
 (0)