在Python中查看字符的ASCII码,你可以使用内置的`ord()`函数。下面是如何使用`ord()`函数查看字符的ASCII码的示例:
```python
查看字符'A'的ASCII码
ascii_value = ord('A')
print(f"The ASCII value of 'A' is {ascii_value}")
如果你想要查看字符串中每个字符的ASCII码,可以这样做:```python查看字符串中每个字符的ASCII码
x = 'ABC'
for char in x:
print(f"The ASCII value of {char} is {ord(char)}")

另外,如果你想要检查一个字符串是否只包含ASCII字符,可以使用`str.isascii()`方法:
```python
检查字符串是否只包含ASCII字符
my_str = 'www.jiyik.com'
if my_str.isascii():
print('The string contains only ASCII characters')
else:
print('The string does NOT contain only ASCII characters')
使用`str.isascii()`方法,如果字符串为空或者字符串中的所有字符都是ASCII字符,则返回`True`,否则返回`False`。
