• Python Snacks
  • Posts
  • A Quick Introduction to Python's Standard Library

A Quick Introduction to Python's Standard Library

Leverage what Python gives you in its massive standard library.

One of the aspects of Python that I really like is how expansive the standard library is.

The language provides several basic operations, such as sorting, file and directory operations, and even date time operations (AKA: “standard library”).

Below I’ve listed some of the more common functions/methods I’ve used in the past (and still do).

  1. File/Directory Operations - using os module (documentation):

Checking file/directory existence

os.path.exists()

Joining file system paths

os.path.join()

Listing files in a directory

os.listdir()

Retrieve an environment variable

os.getenv()

Recursively create/remove directories

os.makedirs()
os.removedirs()

Create/Remove a directory

os.mkdir()
os.rmdir()

Remove a file

os.remove()

Generate file names in a directory tree

os.walk()

  1. String Manipulation Methods (documentation):

Capitalize the string

str.capitalize()

Uppercase the string

str.upper()

Lowercase the string

str.lower()

Remove whitespace around the string

str.strip()

Concatenate a list into a string

str.join()

  1. Datetime Operations - using datetime module (documentation):

Return the current UTC date

datetime.utcnow()^
datetime.now(datetime.UTC)^

Convert a string to a datetime object

datetime.strptime()*

Build a string from a datetime object

datetime.strftime()

^ At some point in Python 3.12.3+, they’ll be removing datetime.utcnow() and replacing it with datetime.now(datetime.UTC).
* Often times, strptime and strftime get confused. Remember: “p” in strptime is “parse”.

  1. Built-in Functions (documentation):

Absolute value

abs()

Print information to the console

print()

Determine length of object

len()

Generate a sequence of numbers

range()

Sum all elements in a list

sum()

Get minimum/maximum from a list

min()
max()

Get the object’s type

type()

Sort a list

sorted()

This is only a snippet of what Python’s standard library has to offer. Even to this day, I don’t know all of the standard library.

Quite frankly, I don’t think anyone knows the standard library entirely.

So what does this mean for you?

This means you don’t have to write all of this “common functionality” code yourself!

📧 Join the Python Snacks Newsletter! 🐍

Want even more Python-related content that’s useful? Here’s 3 reasons why you should subscribe the Python Snacks newsletter:

  1. Get Ahead in Python with bite-sized Python tips and tricks delivered straight to your inbox, like the one above.

  2. Exclusive Subscriber Perks: Receive a curated selection of up to 6 high-impact Python resources, tips, and exclusive insights with each email.

  3. Get Smarter with Python in under 5 minutes. Your next Python breakthrough could just an email away.

You can unsubscribe at any time.

Interested in starting a newsletter or a blog?

Do you have a wealth of knowledge and insights to share with the world? Starting your own newsletter or blog is an excellent way to establish yourself as an authority in your field, connect with a like-minded community, and open up new opportunities.

If TikTok, Twitter, Facebook, or other social media platforms were to get banned, you’d lose all your followers. This is why you should start a newsletter: you own your audience.

This article may contain affiliate links. Affiliate links come at no cost to you and support the costs of this blog. Should you purchase a product/service from an affiliate link, it will come at no additional cost to you.

Reply

or to participate.