Saturday 4 December 2021

Write a program to illustrate data types in PYTHON

 The type indicates set values and operations on those values. In any programming language, the data type specifies what type of value a variable can hold. Fortunately it is not need to specify explicitly data type in Python because it is auto infer.

  1. But if you want to specify type, you can also do it.
  2. The 'type' is used to know type of variable.
  3. In Python the type is set to variable when we assign value to it.
  4. The following example shows use of different data types.

Python has the following data types built-in by default, in these categories:

1.Text Type:   str
2.Numeric Types:  int, float, complex
3.Sequence Types:  list, tuple, range
4.Mapping Type:  dict
5.Set Types:  set, frozenset
6.Boolean Type:   bool
7.Binary Types:  bytes, bytearray, memoryview 

Depending upon situation we use different types in our program.

#If you want to know the data type of a variable, this can be done with type
#In Python, the data type is set when you assign a value to a variable:

x=5
y=10.25
z="hello" 
print(type(x))
print(type(y))
print(type(z))
print("--------------------------------------------------------")
x = str("Hello World") #If you want to specify the data type, you can use the following constructor functions:

#display x:
print(x)

#display the data type of x:
print(type(x)) 

x = range(6)

#display x:
print(x)

#display the data type of x:
print(type(x)) 

the following is output of above program

<class 'int'>
<class 'float'>
<class 'str'>
--------------------------------------------------------
Hello World
<class 'str'>
range(0, 6)
<class 'range'>

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top