Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Automatically Generate A List With The English Alphabet In Python

TODO : Combine with : 264g8rgi1kbj which shows how to get a subset of letters.

TODO : Setup a function where you can pass a letter and a number of letters to add and produce a list from that. - - hr

Sometimes you want to get your hands on all the letters in the english alphabet. Here's how :

** Lowercase

You can generate a list of with the full alphabet of lowercase english letters using :

python
import string

alphabet_lowercase = list(string.ascii_lowercase)

print(alphabet_lowercase)
results start

** Uppercase

Uppercase letters can be had with :

python
import string

  alphabet_uppercase = list(string.ascii_uppercase)

  print(alphabet_uppercase)
results start

** How It Works

The [TODO: Code shorthand span ] and ` string.ascii _ uppercase ` calls each return single strings with their correspondingly cased alphabets. That is, [TODO: Code shorthand span ] and ` ABCDEFGHIJKLMNOPQRSTUVWXYZ ` , respectively.

Wrapping a string in [TODO: Code shorthand span ] splits each character out individually and returns it as a separate item in a list.

So, calling [TODO: Code shorthand span ] is equivalent to calling [TODO: Code shorthand span ] which does the split and generates our list ` ['a', 'b', 'c', ...etc ] `

[TODO: Code shorthand span ] and ` string.ascii _ uppercase ` are "String Constants". Basically, built - in stuff that does't change (even if the locale does TKTKTKT note what locale is).

There are a few other String Constants for digits and punctuation that you can < a href="https : //docs.python.org/3/library/string.html" > check out in the docs < /a > .