At the time of writing this post, there is no release date for Python 4 yet. The next version is going to be 3.9.0 which is scheduled to be released on October 5, 2020, it is planned to have support approximately until October 2025, so the next release after 3.9 should come out somewhere between 2020 and 2025. 4 SCI ImageHDU 61 (800, 800) Float32. Python(x,y) is a free scientific and engineering development software for numerical computations, data analysis and data. Python syntax is very clean, with an emphasis on readability, and uses standard English keywords. The easiest introduction to Python is through Thonny, a Python3 development environment. Open Thonny from the Desktop or applications menu: Thonny gives you a REPL (Read-Evaluate-Print-Loop), which is a prompt you can enter Python commands.
Source code:Lib/uuid.py
This module provides immutable UUID
objects (the UUID
class)and the functions uuid1()
, uuid3()
, uuid4()
, uuid5()
forgenerating version 1, 3, 4, and 5 UUIDs as specified in RFC 4122.
If all you want is a unique ID, you should probably call uuid1()
oruuid4()
. Note that uuid1()
may compromise privacy since it createsa UUID containing the computer's network address. uuid4()
creates arandom UUID.
Depending on support from the underlying platform, uuid1()
may or maynot return a 'safe' UUID. A safe UUID is one which is generated usingsynchronization methods that ensure no two processes can obtain the sameUUID. All instances of UUID
have an is_safe
attributewhich relays any information about the UUID's safety, using this enumeration:
uuid.
SafeUUID
¶safe
¶The UUID was generated by the platform in a multiprocessing-safe way.
unsafe
¶The UUID was not generated in a multiprocessing-safe way.
unknown
¶The platform does not provide information on whether the UUID wasgenerated safely or not.
uuid.
UUID
(hex=None, bytes=None, bytes_le=None, fields=None, int=None, version=None, *, is_safe=SafeUUID.unknown)¶Create a UUID from either a string of 32 hexadecimal digits, a string of 16bytes in big-endian order as the bytes argument, a string of 16 bytes inlittle-endian order as the bytes_le argument, a tuple of six integers(32-bit time_low, 16-bit time_mid, 16-bit time_hi_version,8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-bit node) as thefields argument, or a single 128-bit integer as the int argument.When a string of hex digits is given, curly braces, hyphens,and a URN prefix are all optional. For example, theseexpressions all yield the same UUID:
Exactly one of hex, bytes, bytes_le, fields, or int must be given.The version argument is optional; if given, the resulting UUID will have itsvariant and version number set according to RFC 4122, overriding bits in thegiven hex, bytes, bytes_le, fields, or int.
Comparison of UUID objects are made by way of comparing theirUUID.int
attributes. Comparison with a non-UUID objectraises a TypeError
.
str(uuid)
returns a string in the form12345678-1234-5678-1234-567812345678
where the 32 hexadecimal digitsrepresent the UUID.
UUID
instances have these read-only attributes:
UUID.
bytes
¶The UUID as a 16-byte string (containing the six integer fields in big-endianbyte order).
UUID.
bytes_le
¶The UUID as a 16-byte string (with time_low, time_mid, and time_hi_versionin little-endian byte order).
UUID.
fields
¶A tuple of the six integer fields of the UUID, which are also available as sixindividual attributes and two derived attributes:
Field | Meaning |
---|---|
| the first 32 bits of the UUID |
| the next 16 bits of the UUID |
| the next 16 bits of the UUID |
| the next 8 bits of the UUID |
| the next 8 bits of the UUID |
| the last 48 bits of the UUID |
the 60-bit timestamp | |
| the 14-bit sequence number |
UUID.
hex
¶The UUID as a 32-character hexadecimal string.
UUID.
int
¶The UUID as a 128-bit integer.
UUID.
urn
¶The UUID as a URN as specified in RFC 4122.
UUID.
variant
¶The UUID variant, which determines the internal layout of the UUID. This will beone of the constants RESERVED_NCS
, RFC_4122
,RESERVED_MICROSOFT
, or RESERVED_FUTURE
.
UUID.
version
¶The UUID version number (1 through 5, meaningful only when the variant isRFC_4122
).
UUID.
is_safe
¶An enumeration of SafeUUID
which indicates whether the platformgenerated the UUID in a multiprocessing-safe way.
New in version 3.7.
The uuid
module defines the following functions:
uuid.
getnode
()¶Get the hardware address as a 48-bit positive integer. The first time thisruns, it may launch a separate program, which could be quite slow. If allattempts to obtain the hardware address fail, we choose a random 48-bitnumber with the multicast bit (least significant bit of the first octet)set to 1 as recommended in RFC 4122. 'Hardware address' means the MACaddress of a network interface. On a machine with multiple networkinterfaces, universally administered MAC addresses (i.e. where the secondleast significant bit of the first octet is unset) will be preferred overlocally administered MAC addresses, but with no other ordering guarantees.
Changed in version 3.7: Universally administered MAC addresses are preferred over locallyadministered MAC addresses, since the former are guaranteed to beglobally unique, while the latter are not.
uuid.
uuid1
(node=None, clock_seq=None)¶Generate a UUID from a host ID, sequence number, and the current time. If nodeis not given, getnode()
is used to obtain the hardware address. Ifclock_seq is given, it is used as the sequence number; otherwise a random14-bit sequence number is chosen.
uuid.
uuid3
(namespace, name)¶Generate a UUID based on the MD5 hash of a namespace identifier (which is aUUID) and a name (which is a string).
uuid.
uuid4
()¶Generate a random UUID.
uuid.
uuid5
(namespace, name)¶Generate a UUID based on the SHA-1 hash of a namespace identifier (which is aUUID) and a name (which is a string).
The uuid
module defines the following namespace identifiers for use withuuid3()
or uuid5()
.
uuid.
NAMESPACE_DNS
¶When this namespace is specified, the name string is a fully-qualified domainname.
uuid.
NAMESPACE_URL
¶When this namespace is specified, the name string is a URL.
uuid.
NAMESPACE_OID
¶When this namespace is specified, the name string is an ISO OID.
uuid.
NAMESPACE_X500
¶When this namespace is specified, the name string is an X.500 DN in DER or atext output format.
The uuid
module defines the following constants for the possible valuesof the variant
attribute:
uuid.
RESERVED_NCS
¶Reserved for NCS compatibility.
uuid.
RFC_4122
¶Specifies the UUID layout given in RFC 4122.
uuid.
RESERVED_MICROSOFT
¶Reserved for Microsoft compatibility.
uuid.
RESERVED_FUTURE
¶Reserved for future definition.
See also
This specification defines a Uniform Resource Name namespace for UUIDs, theinternal format of UUIDs, and methods of generating UUIDs.
Example¶
Here are some examples of typical usage of the uuid
module:
Tuple
Tuples are used to store multiple items in a single variable.
Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage.
A tuple is a collection which is ordered and unchangeable.
Tuples are written with round brackets.
Example
Create a Tuple:
print(thistuple)
Tuple Items
Tuple items are ordered, unchangeable, and allow duplicate values.
Tuple items are indexed, the first item has index [0]
, the second item has index [1]
etc.
Ordered
When we say that tuples are ordered, it means that the items have a defined order, and that order will not change.
Unchangeable
Tuples are unchangeable, meaning that we cannot change, add or remove items after the tuple has been created.
Allow Duplicates
Since tuple are indexed, tuples can have items with the same value:
Example
Tuples allow duplicate values:
print(thistuple)
Tuple Length
To determine how many items a tuple has, use the len()
function:
Example
Print the number of items in the tuple:
print(len(thistuple))
Create Tuple With One Item
Python 4 Release Date
To create a tuple with only one item, you have to add a comma after the item, otherwise Python will not recognize it as a tuple.
Example
One item tuple, remember the commma:
print(type(thistuple))
#NOT a tuple
thistuple = ('apple')
print(type(thistuple))
Tuple Items - Data Types
Tuple items can be of any data type:
Example
String, int and boolean data types:
tuple2 = (1, 5, 7, 9, 3)
tuple3 = (True, False, False)
A tuple can contain different data types:
Example
A tuple with strings, integers and boolean values:
Try it Yourself »type()
Python 4 Everybody
From Python's perspective, tuples are defined as objects with the data type 'tuple':
Example
What is the data type of a tuple?
print(type(mytuple))
The tuple() Constructor
It is also possible to use the tuple() constructor to make a tuple.
Example
Using the tuple() method to make a tuple:
print(thistuple)
Colt Python 4
The UUID as a 32-character hexadecimal string.
UUID.
int
¶The UUID as a 128-bit integer.
UUID.
urn
¶The UUID as a URN as specified in RFC 4122.
UUID.
variant
¶The UUID variant, which determines the internal layout of the UUID. This will beone of the constants RESERVED_NCS
, RFC_4122
,RESERVED_MICROSOFT
, or RESERVED_FUTURE
.
UUID.
version
¶The UUID version number (1 through 5, meaningful only when the variant isRFC_4122
).
UUID.
is_safe
¶An enumeration of SafeUUID
which indicates whether the platformgenerated the UUID in a multiprocessing-safe way.
New in version 3.7.
The uuid
module defines the following functions:
uuid.
getnode
()¶Get the hardware address as a 48-bit positive integer. The first time thisruns, it may launch a separate program, which could be quite slow. If allattempts to obtain the hardware address fail, we choose a random 48-bitnumber with the multicast bit (least significant bit of the first octet)set to 1 as recommended in RFC 4122. 'Hardware address' means the MACaddress of a network interface. On a machine with multiple networkinterfaces, universally administered MAC addresses (i.e. where the secondleast significant bit of the first octet is unset) will be preferred overlocally administered MAC addresses, but with no other ordering guarantees.
Changed in version 3.7: Universally administered MAC addresses are preferred over locallyadministered MAC addresses, since the former are guaranteed to beglobally unique, while the latter are not.
uuid.
uuid1
(node=None, clock_seq=None)¶Generate a UUID from a host ID, sequence number, and the current time. If nodeis not given, getnode()
is used to obtain the hardware address. Ifclock_seq is given, it is used as the sequence number; otherwise a random14-bit sequence number is chosen.
uuid.
uuid3
(namespace, name)¶Generate a UUID based on the MD5 hash of a namespace identifier (which is aUUID) and a name (which is a string).
uuid.
uuid4
()¶Generate a random UUID.
uuid.
uuid5
(namespace, name)¶Generate a UUID based on the SHA-1 hash of a namespace identifier (which is aUUID) and a name (which is a string).
The uuid
module defines the following namespace identifiers for use withuuid3()
or uuid5()
.
uuid.
NAMESPACE_DNS
¶When this namespace is specified, the name string is a fully-qualified domainname.
uuid.
NAMESPACE_URL
¶When this namespace is specified, the name string is a URL.
uuid.
NAMESPACE_OID
¶When this namespace is specified, the name string is an ISO OID.
uuid.
NAMESPACE_X500
¶When this namespace is specified, the name string is an X.500 DN in DER or atext output format.
The uuid
module defines the following constants for the possible valuesof the variant
attribute:
uuid.
RESERVED_NCS
¶Reserved for NCS compatibility.
uuid.
RFC_4122
¶Specifies the UUID layout given in RFC 4122.
uuid.
RESERVED_MICROSOFT
¶Reserved for Microsoft compatibility.
uuid.
RESERVED_FUTURE
¶Reserved for future definition.
See also
This specification defines a Uniform Resource Name namespace for UUIDs, theinternal format of UUIDs, and methods of generating UUIDs.
Example¶
Here are some examples of typical usage of the uuid
module:
Tuple
Tuples are used to store multiple items in a single variable.
Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage.
A tuple is a collection which is ordered and unchangeable.
Tuples are written with round brackets.
Example
Create a Tuple:
print(thistuple)
Tuple Items
Tuple items are ordered, unchangeable, and allow duplicate values.
Tuple items are indexed, the first item has index [0]
, the second item has index [1]
etc.
Ordered
When we say that tuples are ordered, it means that the items have a defined order, and that order will not change.
Unchangeable
Tuples are unchangeable, meaning that we cannot change, add or remove items after the tuple has been created.
Allow Duplicates
Since tuple are indexed, tuples can have items with the same value:
Example
Tuples allow duplicate values:
print(thistuple)
Tuple Length
To determine how many items a tuple has, use the len()
function:
Example
Print the number of items in the tuple:
print(len(thistuple))
Create Tuple With One Item
Python 4 Release Date
To create a tuple with only one item, you have to add a comma after the item, otherwise Python will not recognize it as a tuple.
Example
One item tuple, remember the commma:
print(type(thistuple))
#NOT a tuple
thistuple = ('apple')
print(type(thistuple))
Tuple Items - Data Types
Tuple items can be of any data type:
Example
String, int and boolean data types:
tuple2 = (1, 5, 7, 9, 3)
tuple3 = (True, False, False)
A tuple can contain different data types:
Example
A tuple with strings, integers and boolean values:
Try it Yourself »type()
Python 4 Everybody
From Python's perspective, tuples are defined as objects with the data type 'tuple':
Example
What is the data type of a tuple?
print(type(mytuple))
The tuple() Constructor
It is also possible to use the tuple() constructor to make a tuple.
Example
Using the tuple() method to make a tuple:
print(thistuple)
Colt Python 4
Try it Yourself »Python Collections (Arrays)
There are four collection data types in the Python programming language:
- List is a collection which is ordered and changeable. Allows duplicate members.
- Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
- Set is a collection which is unordered and unindexed. No duplicate members.
- Dictionary is a collection which is ordered* and changeable. No duplicate members.
*As of Python version 3.7, dictionaries are ordered. In Python 3.6 and earlier, dictionaries are unordered.
When choosing a collection type, it is useful to understand the properties of that type. Choosing the right type for a particular data set could mean retention of meaning, and, it could mean an increase in efficiency or security.