0

I am very new to Python.Is there any method through which i can find out which type of value is stored in a particular variable?

In below code how to find out type of stored value in a variable?

counter = 100 miles = 1000.0 name = "John" name =10 print counter print miles print name 
2
  • 3
    print type(counter) ? Commented Nov 14, 2017 at 6:50
  • use Type function. You can check it here stackoverflow.com/questions/402504/… Commented Nov 14, 2017 at 6:53

2 Answers 2

1
>>> type('1') <class 'str'> >>> type(1) <class 'int'> >>> type(1.000) <class 'float'> >>> type({1:2}) <class 'dict'> >>> type([1,2,3]) <class 'list'> 
Sign up to request clarification or add additional context in comments.

Comments

1

Quite simply, use type command built into python.

For example, you could check the type of this variable:

>>> name = 'John' >>> print(type(name)) <class 'str'> 

Use this method wherever you want on a variable, and you don't necessarily have to print it. You could use it to do different things with different variables based on what type it is, for example.

Hoped this helped :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.