Lỗi int object is not callable la gi

As the name suggests, the error TypeError: builtin_function_or_method object is not subscriptable is a “typeerror” that occurs when you try to call a built-in function the wrong way.

When a "typeerror" occurs, the program is telling you that you’re mixing up types. That means, for example, you might be concatenating a string with an integer.

In this article, I will show you why the TypeError: builtin_function_or_method object is not subscriptable occurs and how you can fix it.

Every built-in function of Python such as print(), append(), sorted(), max(), and others must be called with parenthesis or round brackets (()).

If you try to use square brackets, Python won't treat it as a function call. Instead, Python will think you’re trying to access something from a list or string and then throw the error.

For example, the code below throws the error because I was trying to print the value of the variable with square braces in front of the print() function:

And if you surround what you want to print with square brackets even if the item is iterable, you still get the error:

gadgets = ["Mouse", "Monitor", "Laptop"]
print[gadgets[0]]
# Output: Traceback (most recent call last):
#   File "built_in_obj_not_subable.py", line 2, in <module>
#     print[gadgets[0]]
# TypeError: 'builtin_function_or_method' object is not subscriptable

This issue is not particular to the print() function. If you try to call any other built-in function with square brackets, you also get the error.

In the example below, I tried to call max() with square brackets and I got the error:

numbers = [5, 7, 24, 6, 90]
max_num = max(numbers)
print[max_num]
# Traceback (most recent call last):
#   File "built_in_obj_not_subable.py", line 11, in <module>
#     print[max_num]
# TypeError: 'builtin_function_or_method' object is not subscriptable

How to Fix the TypeError: builtin_function_or_method object is not subscriptable Error

To fix this error, all you need to do is make sure you use parenthesis to call the function.

You only have to use square brackets if you want to access an item from iterable data such as string, list, or tuple:

gadgets = ["Mouse", "Monitor", "Laptop"]
print(gadgets[0])
# Output: Mouse
numbers = [5, 7, 24, 6, 90]
max_num = max(numbers)
print(max_num)
# Output: 90

Wrapping Up

This article showed you why the TypeError: builtin_function_or_method object is not subscriptable occurs and how to fix it.

Remember that you only need to use square brackets (

numbers = [5, 7, 24, 6, 90]
max_num = max(numbers)
print[max_num]
# Traceback (most recent call last):
#   File "built_in_obj_not_subable.py", line 11, in <module>
#     print[max_num]
# TypeError: 'builtin_function_or_method' object is not subscriptable

  1. to access an item from iterable data and you shouldn't use it to call a function.

If you’re getting this error, you should look in your code for any point at which you are calling a built-in function with square brackets and replace it with parenthesis.

Thanks for reading.



Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

This is a common coding error that occurs when you declare a variable with the same name as inbuilt int() function used in the code. Python compiler gets confused between variable 'int' and function int() because of their similar names and therefore throws typeerror: 'int' object is not callable error.

To overcome this problem, you must use unique names for custom functions and variables.

Example

`

Error Code

Declaring and Initializing a variable

int = 5;

Taking input from user {Start}

productPrice = int(input("Enter the product price : ")) productQuantity = int(input("Enter the number of products : "))

Taking input from user {Ends}

variable to hold the value of effect on the balance sheet

after purchasing this product.

costOnBalanceSheet = productPrice * productQuantity

printing the output

print(costOnBalanceSheet) `

Output

Enter the product price : 2300 Traceback (most recent call last):   File "C:\Users\Webartsol\AppData\Local\Programs\Python\Python37-32\intObjectnotCallable.py", line 3, in <module>     productPrice = int(input("Enter the product price : ")) TypeError: 'int' object is not callable

In the example above we have declared a variable named `int` and later in the program, we have also used the Python inbuilt function int() to convert the user input into int values.

Python compiler takes “int” as a variable, not as a function due to which error “TypeError: 'int' object is not callable” occurs.

How to resolve typeerror: 'int' object is not callable

To resolve this error, you need to change the name of the variable whose name is similar to the in-built function int() used in the code.