How do I create a GUID / UUID?

 

In Python, you can generate a GUID (Globally Unique Identifier) or UUID (Universally Unique Identifier) using the uuid module. Here's how you can generate a UUID with an example:

python
import uuid # Generate a UUID new_uuid = uuid.uuid4() # Print the generated UUID print("Generated UUID:", new_uuid)

In this example, the uuid.uuid4() function generates a random UUID using the version 4 algorithm. The resulting UUID is a unique identifier that is highly unlikely to collide with any other UUID generated in the same or different systems.

When you run the code, you'll see the generated UUID printed to the console, similar to this:

yaml
Generated UUID: 2a9a3bc5-33f1-4a2d-85cc-6e9959e093e3

Every time you run the code, a new and unique UUID will be generated. This makes UUIDs useful for creating identifiers that are likely to be unique across various systems and timeframes.

Comments