Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีเช็คว่า String มีเฉพาะ Lowercase Letters ใน Python

1. ใช้ islower()

>> 'Hello world'.islower()
False
>>> 'hello world'.islower()
True

2. ใช้ Regex ^[a-z]+$

>> import re
>>> bool(re.match('^[a-z]+$', '123abc'))
False
>>> bool(re.match('^[a-z]+$', 'abc'))
True