Yes, there is a difference. Although in Python 3, all objects are instances of object, including object itself, only Any documents that the return value should be disregarded by the typechecker.

The Any type docstring states that object is a subclass of Any and vice-versa:

>>> import typing
>>> print(typing.Any.__doc__)
Special type indicating an unconstrained type.

    - Any object is an instance of Any.
    - Any class is a subclass of Any.
    - As a special case, Any and object are subclasses of each other.

However, a proper typechecker (one that goes beyond isinstance() checks, and which inspects how the object is actually used in the function) can readily object to object where Any is always accepted.

From the Any type documentation:

Notice that no typechecking is performed when assigning a value of type Any to a more precise type.

and

Contrast the behavior of Any with the behavior of object. Similar to Any, every type is a subtype of object. However, unlike Any, the reverse is not true: object is not a subtype of every other type.

That means when the type of a value is object, a type checker will reject almost all operations on it, and assigning it to a variable (or using it as a return value) of a more specialized type is a type error.

and from the mypy documentation section Any vs. object:

The type object is another type that can have an instance of arbitrary type as a value. Unlike Any, object is an ordinary static type (it is similar to Object in Java), and only operations valid for all types are accepted for object values.

object can be cast to a more specific type, while Any really means anything goes and a type checker disengages from any use of the object (even if you later assign such an object to a name that is typechecked).

You already painted your function into a an un-typed corner by accepting list, which comes down to being the same thing as List[Any]. The typechecker disengaged there and the return value no longer matters, but since your function accepts a list containing Any objects, the proper return value would be Any here.

To properly participate in type-checked code, you need to mark your input as List[T] (a genericly typed container) for a typechecker to then be able to care about the return value. Which in your case would be T since you are retrieving a value from the list. Create T from a TypeVar:

from typing import TypeVar, List

T = TypeVar('T')

def get_item(L: List[T], i: int) -> T:
    return L[i]

or, using Python 3.12 or newer:

def get_itemT -> T:
    return L[i]
Answer from Martijn Pieters on Stack Overflow
🌐
Python documentation
docs.python.org › 3 › library › typing.html
typing — Support for type hints
1 week ago - The Python typing system is standardised via PEPs, so this reference should broadly apply to most Python type checkers. (Some parts may still be specific to mypy.) ... Type-checker-agnostic documentation written by the community detailing type system features, useful typing related tools and typing best practices.
Top answer
1 of 2
151

Yes, there is a difference. Although in Python 3, all objects are instances of object, including object itself, only Any documents that the return value should be disregarded by the typechecker.

The Any type docstring states that object is a subclass of Any and vice-versa:

>>> import typing
>>> print(typing.Any.__doc__)
Special type indicating an unconstrained type.

    - Any object is an instance of Any.
    - Any class is a subclass of Any.
    - As a special case, Any and object are subclasses of each other.

However, a proper typechecker (one that goes beyond isinstance() checks, and which inspects how the object is actually used in the function) can readily object to object where Any is always accepted.

From the Any type documentation:

Notice that no typechecking is performed when assigning a value of type Any to a more precise type.

and

Contrast the behavior of Any with the behavior of object. Similar to Any, every type is a subtype of object. However, unlike Any, the reverse is not true: object is not a subtype of every other type.

That means when the type of a value is object, a type checker will reject almost all operations on it, and assigning it to a variable (or using it as a return value) of a more specialized type is a type error.

and from the mypy documentation section Any vs. object:

The type object is another type that can have an instance of arbitrary type as a value. Unlike Any, object is an ordinary static type (it is similar to Object in Java), and only operations valid for all types are accepted for object values.

object can be cast to a more specific type, while Any really means anything goes and a type checker disengages from any use of the object (even if you later assign such an object to a name that is typechecked).

You already painted your function into a an un-typed corner by accepting list, which comes down to being the same thing as List[Any]. The typechecker disengaged there and the return value no longer matters, but since your function accepts a list containing Any objects, the proper return value would be Any here.

To properly participate in type-checked code, you need to mark your input as List[T] (a genericly typed container) for a typechecker to then be able to care about the return value. Which in your case would be T since you are retrieving a value from the list. Create T from a TypeVar:

from typing import TypeVar, List

T = TypeVar('T')

def get_item(L: List[T], i: int) -> T:
    return L[i]

or, using Python 3.12 or newer:

def get_itemT -> T:
    return L[i]
2 of 2
45

Any and object are superficially similar, but in fact are entirely opposite in meaning.

object is the root of Python's metaclass hierarchy. Every single class inherits from object. That means that object is in a certain sense the most restrictive type you can give values. If you have a value of type object, the only methods you are permitted to call are ones that are a part of every single object. For example:

foo: object = 3

# Error, not all objects have a method 'hello'
bar = foo.hello()   

# OK, all objects have a __str__ method
print(str(foo))   

In contrast, Any is an escape hatch meant to allow you to mix together dynamic and statically typed code. Any is the least restrictive type -- any possible method or operation is permitted on a value of type Any. For example:

from typing import Any
foo: Any = 3

# OK, foo could be any type, and that type might have a 'hello' method
# Since we have no idea what hello() is, `bar` will also have a type of Any
bar = foo.hello()

# Ok, for similar reasons
print(str(foo))

You should generally try and use Any only for cases where...

  1. As a way of mixing together dynamic and statically typed code. For example, if you have many dynamic and complex functions, and don't have time to fully statically type all of them, you could settle for just giving them a return type of Any to nominally bring them into the typechecked work. (Or to put it another way, Any is a useful tool for helping migrate an untypechecked codebase to a typed codebase in stages).
  2. As a way of giving a type to an expression that is difficult to type. For example, Python's type annotations currently do not support recursive types, which makes typing things like arbitrary JSON dicts difficult. As a temporary measure, you might want to give your JSON dicts a type of Dict[str, Any], which is a bit better then nothing.

In contrast, use object for cases where you want to indicate in a typesafe way that a value MUST literally work with any possible object in existence.

My recommendation is to avoid using Any except in cases where there is no alternative. Any is a concession -- a mechanism for allowing dynamism where we'd really rather live in a typesafe world.

For more information, see:

  • https://docs.python.org/3/library/typing.html#the-any-type
  • http://mypy.readthedocs.io/en/latest/kinds_of_types.html#the-any-type

For your particular example, I would use TypeVars, rather then either object or Any. What you want to do is to indicate that you want to return the type of whatever is contained within the list. If the list will always contain the same type (which is typically the case), you would want to do:

from typing import List, TypeVar

T = TypeVar('T')
def get_item(L: List[T], i: int) -> T:
    return L[i]

This way, your get_item function will return the most precise type as possible.

Discussions

How am I supposed to do type annotation in Python when it's all Any type?
Python very much cares about types, it is a strongly typed language but is dynamically typed. Admittedly this can cause problems in substantial code bases which is why some large companies have put work into typing, notably Facebook and Dropbox. It is worth keeping in mind that variables don't have type as they do not hold any values, only memory references (pointers, if you prefer) to Python objects and it is the latter that has types. Similarly container objects, like lists, are collections of memory references. Some libraries are just lazily written and others explicitly intended to take full advantage of the dynamic typing nature of Python. Regarding beautifulsoup, you are not the only one trying to wrestle with it for type checking. For example, https://skeptric.com/typing-beautiful-soup/ More on reddit.com
🌐 r/learnpython
9
4
May 28, 2021
Typing: `object` vs `Any` (and `None` as a default)
I have a function with a parameter that represents an arbitrary value returned by a user defined function. Based on the typing docs, my understanding is that the correct typing for the value would be object instead of Any. Is that correct? I want that the parameter to have None as a default value. More on discuss.python.org
🌐 discuss.python.org
0
April 11, 2025
Will typing objects like `Any` or `Never` ever become built-ins?
actually, before 3.9, you had to import List, Dict, and Tuple from typing as well. check PEP 585 to read about the reasons for allowing built-in types to handle generic type hints directly. we’re basically headed towards deprecating typing but some types like Union are a bit different since they’re not related to built-in containers. maybe we’ll just have syntactic sugar for those like the one you described. More on reddit.com
🌐 r/learnpython
13
16
September 14, 2024
Python typing, what's the difference between dict[any,str] and dict(any,str)?
No, they're not the same thing. The latter shouldn't even work because dict expects named arguments. If you're using a Python version older than 3.9, you need to use typing.Dict for type hints instead of dict. So in this case, from typing import Any, Dict def example_function(variable: Dict[Any, str]): ... Are you sure that's the right way around, though? Usually I see dictionaries with strings as keys and the values being all kinds of types. More on reddit.com
🌐 r/learnpython
8
1
November 26, 2021
🌐
Python.org
discuss.python.org › ideas
Making Any a builtin object, referring to typing.Any - Ideas - Discussions on Python.org
March 29, 2022 - Has there been active discussion of making Any a keyword in the language? Now that 3.6 is EOL, I’m finding a lot of my projects are making changes like so: +from __future__ import annotations + -from typing import Optional, Any, Dict +from typing import Any class Foo: - bar: Optional[Dict[str, Any]] + bar: dict[str, Any] | None This is happening in many modules across several different kinds of projects – libraries and applications.
🌐
Python
typing.python.org › en › latest › spec › special-types.html
Special types in annotations — typing documentation
When used in a type hint, the expression None is considered equivalent to type(None). The typing module provides a special form NoReturn to annotate functions that never return normally.
🌐
Reddit
reddit.com › r/learnpython › how am i supposed to do type annotation in python when it's all any type?
r/learnpython on Reddit: How am I supposed to do type annotation in Python when it's all Any type?
May 28, 2021 -

So for example, I am using BeautifulSoup library. And unlike other statically typed languages, no one seems to care about types in Python so the documentation does not tell me what's the return type of a function.

from bs4 import BeautifulSoup

soup =  BeautifulSoup(self.driver.page_source, "html.parser")
result = soup.find("pre").text

I use VSCode as my IDE, and when I hover over variables soup and result, it says unknown. So how am I supposed to annotate those types?

🌐
Python.org
discuss.python.org › python help
Typing: `object` vs `Any` (and `None` as a default) - Python Help - Discussions on Python.org
April 11, 2025 - I have a function with a parameter that represents an arbitrary value returned by a user defined function. Based on the typing docs, my understanding is that the correct typing for the value would be object instead of An…
Find elsewhere
🌐
FastAPI
fastapi.tiangolo.com › python-types
Python Types Intro - FastAPI
You can declare all the standard Python types, not only str. ... def get_items(item_a: str, item_b: int, item_c: float, item_d: bool, item_e: bytes): return item_a, item_b, item_c, item_d, item_e · For some additional use cases, you might need to import some things from the standard library typing module, for example when you want to declare that something has "any type", you can use Any from typing:
🌐
Reddit
reddit.com › r/learnpython › will typing objects like `any` or `never` ever become built-ins?
r/learnpython on Reddit: Will typing objects like `Any` or `Never` ever become built-ins?
September 14, 2024 -

I'm learning to use a linter to make my code more consistent, and I've been learning more about type-hinting because of that.

In order to make my linter happy, I need to add return types to all my functions and methods. For most of them this is easy (int, None, tuple[int, int]) etc. however it seems like it's actually impossible to properly type-hint certain functions without importing the typing module, to access those extra hinting types.

I know you used to have to import this module to do things like unions (which you can now do with something like int|list[int, ...]). And I wonder if these typing-specific objects could ever be made into a built-in that doesn't require an import (the same way many other named objects like None, NotImplemented, Ellipses, or many others, are).

I know people here probably can't give me a certain answer, I'm just looking to talk about it because I'm curious :)

🌐
Adam Johnson
adamj.eu › tech › 2021 › 05 › 07 › python-type-hints-use-object-instead-of-any
Python type hints: Use object instead of Any - Adam Johnson
If you’re using Any to mean “this object could be any type, and I don’t care what”, you probably want to use object instead. Every object in Python inherits from object, which makes it an “opaque” type that only allows operations common to everything.
🌐
Mypy
mypy.readthedocs.io › en › stable › cheat_sheet_py3.html
Type hints cheat sheet - mypy 1.19.1 documentation
# For most types, just use the name of the type in the annotation # Note that mypy can usually infer the type of a variable from its value, # so technically these annotations are redundant x: int = 1 x: float = 1.0 x: bool = True x: str = "test" x: bytes = b"test" # For collections on Python 3.9+, the type of the collection item is in brackets x: list[int] = [1] x: set[int] = {6, 7} # For mappings, we need the types of both keys and values x: dict[str, float] = {"field": 2.0} # Python 3.9+ # For tuples of fixed size, we specify the types of all the elements x: tuple[int, str, float] = (3, "yes
🌐
Python
typing.python.org › en › latest › spec › concepts.html
Type system concepts — typing documentation
For example, a dictionary can be ... runtime checking of the value type. A gradual type system is one in which a special “unknown” or “dynamic” type is used to describe names or expressions whose types are not known statically. In Python, this type is spelled ...
🌐
Dagster
dagster.io › blog › python-type-hinting
Using Type Hinting in Python Projects
For example, you can declare a variable and directly assign a value to it without specifying its type, hence the term 'dynamically-typed'. Python interpreter implicitly binds the value and its type at runtime.
🌐
Plain English
python.plainenglish.io › 5-python-type-hints-every-data-scientist-needs-a51b4d3f8c15
5 Python Type Hints Every Data Scientist Needs | by Jaume Boguñá | Python in Plain English
November 24, 2025 - In this article, I share 5 practical ways to write better type hints, using a small book dataset to make the examples concrete and reproducible.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-data-types
Python Data Types - GeeksforGeeks
Each assignment replaces previous value, making 'x' take on data type and value of most recent assignment. ... x = 50 # int x = 60.5 # float x = "Hello World" # string x = ["geeks", "for", "geeks"] # list x = ("geeks", "for", "geeks") # tuple · Python numbers represent data that has a numeric value.
Published   October 15, 2025
🌐
Pyrefly
pyrefly.org › python typing 101
Python Typing 101 | Pyrefly
Understanding types helps you predict how your code will behave and avoid runtime errors from trying to perform operations that don't make sense, such as dividing a string by a number. A type hint in Python is a way to indicate the expected data type of a variable, function parameter, or return value.
🌐
Jared Khan
jaredkhan.com › blog › resist-the-any-type
Python Typing: Resisting the Any type | Jared Khan
August 29, 2020 - With typing in Python, we aim to restrict as many invalid programs as possible before they’re ever run. This post covers some useful features for tightening up our types: TypeVar for when an unknown type appears multiple times in the same context [Jump]
🌐
Python
docs.python.org › 3.9 › library › typing.html
typing — Support for type hints — Python 3.9.24 documentation
Use object to indicate that a value could be any type in a typesafe manner. Use Any to indicate that a value is dynamically typed. Initially PEP 484 defined the Python static type system as using nominal subtyping.
🌐
Python
peps.python.org › pep-0484
PEP 484 – Type Hints | peps.python.org
For example, the type “sequence of integers” can be written as Sequence[int]. The square brackets mean that no new syntax needs to be added to the language. The example here uses a custom type Sequence, imported from a pure-Python module typing. The Sequence[int] notation works at runtime by implementing __getitem__() in the metaclass (but its significance is primarily to an offline type checker).
🌐
Adam Johnson
adamj.eu › tech › 2021 › 06 › 14 › python-type-hints-3-somewhat-unexpected-uses-of-typing-any-in-pythons-standard-library
Python type hints: three somewhat unexpected uses of typing.Any in Python’s standard library - Adam Johnson
June 14, 2021 - We’ve seen that the pesky Any type may be “hiding” in APIs that are normally well-typed, but offer some flexibility. We need to take care when using such functions. As type hints spread through the Python ecosystem, we may see such APIs changed to allow stricter typing in the common cases.