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


沒有留言:

張貼留言

[Linux 文章收集] Linux / Unix: Check Last Time User Logged In On The System

Source From  Here   Question   I am a new Unix system admin. How do I find ouw who has recently use the Linux or Unix-like server?  Which te...