How to check whether something is a variable or a function in Python

0 votes
Suppose I have something in Python called xyz. Now it could be a variable or a function. So how to check this?
Jul 30, 2019 in Python by Neel
• 3,020 points

1 answer to this question.

0 votes

Suppose you have a variable defined in Python. Now to verify this you can use type and callable.

a = 12
type(a) # prints int. 
callable(a) # prints false as it is not a function

Now suppose you have a function defined in python. to verify this you can refer the following 

def my_func():
  print("Hello, World!")
type(my_func) # prints function
callable(my_func) # prints true as it is a function

answered Jul 30, 2019 by Arvind
• 3,040 points

Related Questions In Python

0 votes
1 answer

How does Python know whether a variable in the class is a method or a variable?

In python objects/variables are wrapped into methods ...READ MORE

answered Sep 18, 2018 in Python by aryya
• 7,450 points
0 votes
0 answers

How to check whether a variable is a class or not?

I was wondering how to check whether ...READ MORE

Nov 24, 2022 in Python by sarit
• 1,830 points
+1 vote
1 answer

How to check if a string is null in python

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

answered Aug 20, 2018 in Python by Priyaj
• 58,090 points
0 votes
1 answer

How do I use urllib to see if a website is 404 or 200 in Python?

For Python 3, try doing this: import urllib.request, ...READ MORE

answered Nov 29, 2018 in Python by Nymeria
• 3,560 points

edited Dec 11, 2018 by Nymeria 13,606 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,184 views
0 votes
1 answer
0 votes
2 answers

How to check whether a string contains alphabets or number in Python?

By using isAlpha () to check whether ...READ MORE

answered Jul 14, 2019 in Python by Sheik janibasha
0 votes
4 answers

how to sort a list of numbers without using built-in functions like min, max or any other function?

Yes it is possible. You can refer ...READ MORE

answered Jun 27, 2019 in Python by Arvind
• 3,040 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP