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 in Python by Neel
• 3,010 points
27 views

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 by Arvind
• 2,960 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 ariaholic
• 7,340 points
52 views
+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
• 56,900 points
3,660 views
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,520 points

edited Dec 11, 2018 by Nymeria 867 views
0 votes
1 answer

How do I check if input string is a valid regular expression or not in Python?

Hi. Good question! Well, just like what ...READ MORE

answered Feb 12 in Python by Nymeria
• 3,520 points
101 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 287 views
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 13 in Python by Sheik janibasha
65 views
0 votes
1 answer