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
, andcomplex
. 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
, andrange
. 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
andfrozenset
. 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 valuesTrue
andFalse
.
Example:
my_bool = True # bool
- Binary Types:
Python has two built-in binary types:
bytes
andbytearray
. 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