2018年3月29日 星期四

[ Python 常見問題 ] How do I iterate through the alphabet in Python?

Source From Here 
Question 
As title. How do I iterate a-z without creating my own list of chars? 

How-To 
You can use string.ascii_lowercase which is simply a convenience string of lowercase letters: 
>>> from string import ascii_lowercase 
>>> ascii_lowercase 
'abcdefghijklmnopqrstuvwxyz' 
>>> for c in ascii_lowercase: 
... print('Char {}'.format(c)) 
... 
Char a 
Char b 
... 
Char z


沒有留言:

張貼留言

[ Python 文章收集 ] SQLAlchemy quick start with PostgreSQL

Source From   Here   Preface   This is a quick tutorial for getting started with   SQLAlchemy Core API .   Prerequisites   In this quick st...