Built-in Objects in Python-builtins


Python has a number of built-in objects that are available for use without the need for importing any external libraries or modules. Some of the most commonly used built-in objects in Python are:

  • Numeric Types: Python has three built-in numeric types: int, float, and complex. These are used to represent integers, floating-point numbers, and complex numbers respectively.

Example:

a = 5 # int
b = 3.14 # float
c = 2 + 3j # complex
  • Sequence Types: Python has several built-in sequence types, including list, tuple, and range. These are used to represent ordered collections of items.

Example:

my_list = [1, 2, 3] # list
my_tuple = (4, 5, 6) # tuple
my_range = range(0, 10, 2) # range
  • Text Type: Python has a built-in text type called str, which is used to represent strings of characters.

Example:

my_string = "Hello, World!" # str
  • Mapping Type: Python has a built-in mapping type called dict, which is used to represent key-value pairs.

Example:

my_dict = {"name": "John", "age": 30} # dict
  • Set Types: Python has two built-in set types: set and frozenset. These are used to represent unordered collections of unique items.

Example:

my_set = {1, 2, 3} # set
my_frozenset = frozenset([4, 5, 6]) # frozenset
  • Boolean Type: Python has a built-in boolean type called bool, which is used to represent the truth values True and False.

Example:

my_bool = True # bool
  • Binary Types: Python has two built-in binary types: bytes and bytearray. These are used to represent sequences of bytes.

Example:

my_bytes = b"hello" # bytes
my_bytearray = bytearray(b"world") # bytearray
  • None Type: Python has a built-in type called NoneType, which is used to represent the absence of a value.

Example:

my_none = None # NoneType


About the author

William Pham is the Admin and primary author of Howto-Code.com. With over 10 years of experience in programming. William Pham is fluent in several programming languages, including Python, PHP, JavaScript, Java, C++.