• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Using Python to Print Variable Type

Using Python to Print Variable Type

August 29, 2022 Leave a Comment

To print the variable type of a variable in Python, you can use the type() function to get the type and print it with print().

a = 1
b = "string"
c = [0, 1, 2]
d = (0, 1, 2)
e = {"key":"value"}
f = 1.0
g = {"set"}

print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
print(type(f))
print(type(g))

#Output:
<class 'int'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'dict'>
<class 'float'>
<class 'set'>

When working with different objects in Python, the ability to check the type of your variables and objects easily is very important.

In Python, you can easily get the variable type and print it.

type() is a built-in function that helps you find the class type of the given variable.

To print the variable type of a variable in Python, you can use the type() function to get the type and print it with print().

Below shows you how to print the variable type of different objects in Python.

a = 1
b = "string"
c = [0, 1, 2]
d = (0, 1, 2)
e = {"key":"value"}
f = 1.0
g = {"set"}

print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
print(type(f))
print(type(g))

#Output:
<class 'int'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'dict'>
<class 'float'>
<class 'set'>

Hopefully this article has been useful for you to learn how to print the type of a variable in Python.

Other Articles You'll Also Like:

  • 1.  Get Days in Month Using Python
  • 2.  Python Remove First Element from List
  • 3.  Python Coin Flip – How to Simulate Flipping a Coin in Python
  • 4.  Get Python Dictionary Values as List
  • 5.  How to Divide Two Numbers in Python
  • 6.  Python Print List – Printing Elements of List to the Console
  • 7.  Create Empty File with Python
  • 8.  Get List of Letters in Alphabet with Python
  • 9.  Get pandas Column Names as List in Python
  • 10.  Skip Numbers in Python Range

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy