Wednesday, October 11, 2023

Python’s Built-in Modules

Python’s Standard Library

It is there so that developers can focus on the task in hand and not sit to re-invent the wheel for common task.

Core Ideas:

- Reusability

- Standardization of code

Some commonly used modules are as given below:

# There is one for Math – as in 'math' used for constants like math.pi

# There is one for Statistics – as in statistics.mean()

# random

# “string” – for string templates like ascii_lower

# collections

# Itertools

# “dateutil” - as in dateutil.parser.parse()




import string
string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
l = [chr(i) for i in range(ord('a'), ord('z') + 1)]
print(l)

['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

s = ""
for i in range(ord('a'), ord('z') + 1): s += chr(i)
print(s)
abcdefghijklmnopqrstuvwxyz    

String Classes Available in The Form of String Templates

print(string.digits)

0123456789

#

print(string.ascii_lowercase)

abcdefghijklmnopqrstuvwxyz

#

print(string.ascii_uppercase)

ABCDEFGHIJKLMNOPQRSTUVWXYZ

#

print(string.ascii_letters)

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

#

print(string.printable)

0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

#

print(string.hexdigits)

0123456789abcdefABCDEF

#

print(string.octdigits)

01234567

No comments:

Post a Comment