Python TypeError: 'int' object is not callable

Asked 1 weeks ago, Updated 1 weeks ago, 0 views

I'm Corinne, and I've never done coding before.

I have to use datetime to call up the time and make a program that changes the greeting depending on the time, so what's the problem?

python

2022-09-20 11:06

1 Answers

datetime.hour is an attribute, not a method. If you use a call expression for something other than a method or function, an error occurs. Almost all languages are common.

https://docs.python.org/3/library/datetime.html#datetime.datetime.hour

Please run the code below:

import datetime
time = datetime.datetime.now()

print(time)

print('time.hour:', time.hour)
# # print('time.hour():', time.hour())

If you read the message carefully, you can see the line and the cause of the error.

TypeError: 'int' object is not callable is caused by an error of type TypeError and the int data type is called as a function... That's what it means.


2022-09-20 11:06

If you have any answers or tips


© 2022 pinfo. All rights reserved.