×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Create number variables (int, float and complex) and print their types and values in Python

Here, we are going to learn how to create number variables to store integer, float and complex numbers in Python, how to print their types and values? By IncludeHelp Last updated : April 08, 2023

Creating Numeric Types Variables

The task is to create number variables to store integer, float and complex number, we have to print their types and values also in python.

Python numbers

There are three types of numbers in python:

  1. Integer number
  2. Float number
  3. Complex number

In the below-given program, we are creating different variables to store the numbers and printing their types (using the type() method) and values.

Python program to create number variables, print their types and values

# Python code to create number variables, 
# print types and values

# creating number variables and assigning values
a = 10      # integer
b = 10.23   # float 
c = 10+2j   # complex

# printing types
print("type(a): ", type(a))
print("type(b): ", type(b))
print("type(c): ", type(c))

# printing values
print("value of a: ", a)
print("value of b: ", b)
print("value of c: ", c)

Output

type(a):  <class 'int'>
type(b):  <class 'float'>
type(c):  <class 'complex'>
value of a:  10
value of b:  10.23
value of c:  (10+2j)

Assigning integer number in binary, decimal, octal, and hexadecimal format

# Assigning integer number in binary, decimal, 
# octal, and hexadecimal format

# creating integer variables and assigning values
# in different format
a = 123     # integer (decimal format)
b = 0o123   # integer (octal format)
c = 0x123AF # integer (hexadecimal format)
d = 0b11101 # integer binary format

# printing types
print("type(a): ", type(a))
print("type(b): ", type(b))
print("type(c): ", type(c))
print("type(d): ", type(d))

# printing values
print("value of a: ", a)
print("value of b: ", b)
print("value of c: ", c)
print("value of d: ", d)

Output

type(a):  <class 'int'>
type(b):  <class 'int'>
type(c):  <class 'int'>
type(d):  <class 'int'>
value of a:  123
value of b:  83
value of c:  74671
value of d:  29

Python Basic Programs »

Advertisement
Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.