Python3 中的 isalpha()函数

首页 / Python3入门教程 / Python3 中的 isalpha()函数

如果字符串中的所有字符均为字母,Python的 isalpha()方法将返回true。如果字符不是字母,则返回False。它返回True或False。

isalpha - 语法

isalpha - 返回

它返回True或False。

让无涯教程看一下isalpha()方法的一些例子,以了解其功能。

# Python isalpha() method example
# 变量声明
str = "Learnfk"
# 函数调用
str2 = str.isalpha()
# 显示结果
print(str2)

输出

True
isalpha - Python String isalpha()方法示例2
# Python isalpha() method example
# 变量声明
str = "Welcome to the Learnfk"
# 函数调用
str2 = str.isalpha()
# 显示结果
print(str2)

输出

False
isalpha - Python String isalpha()方法示例3
# Python isalpha() method example
# 变量声明
str = "Learnfk"
if str.isalpha() == True:
    print("String contains alphabets")
else: print("Stringn contains other chars too.")

输出

String contains alphabets

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

玩转Spring全家桶 -〔丁雪丰〕

高并发系统设计40问 -〔唐扬〕

性能工程高手课 -〔庄振运〕

Go 并发编程实战课 -〔晁岳攀(鸟窝)〕

人人都用得上的写作课 -〔涵柏〕

打造爆款短视频 -〔周维〕

超级访谈:对话张雪峰 -〔张雪峰〕

手把手带你搭建推荐系统 -〔黄鸿波〕

结构学习力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)