Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何检测一个字符串是否为数字 #12

Open
Sogrey opened this issue Feb 14, 2020 · 0 comments
Open

如何检测一个字符串是否为数字 #12

Sogrey opened this issue Feb 14, 2020 · 0 comments

Comments

@Sogrey
Copy link
Owner

Sogrey commented Feb 14, 2020

s1 = '12345'
print('12345是数字:',s1.isdigit())  ##12345是数字: True

print(int(s1))   ##12345

s2 = '12345a'
print('12345a是数字:',s2.isdigit())  ##12345a是数字: False
print('12345a是字母数字混合形式:',s2.isalnum())  ##12345a是字母数字混合形式: True
s3 = '12_345a'
print('12_345a是字母数字混合形式:',s3.isalnum())  ##12_345a是字母数字混合形式: False

print("     ".isspace())   ## True

print("12.45".isdecimal())  # 检测字符串中是否为整数 ## False
print("abc3d".isalpha())   # 检测字符串中是否为纯字母 ## False
@Sogrey Sogrey added this to Python 基础 in Python QAs Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Python QAs
Python 基础
Development

No branches or pull requests

1 participant