Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
Goeduhub's Online Courses @ Udemy in Just INR 570/-
Online Training - Youtube Live Class Link
0 like 0 dislike
3.3k views
in RTU/BTU B.Tech(CSE-VI SEM) PYTHON LAB by Goeduhub's Expert (7.6k points)

What do you mean by datatype and what are its types ? What are the basic data types in Python? What are the supported data type in Python?

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

3.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon
    More Courses

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Python program to demonstrate basic data-type in python

Data type defines the kind of a value i.e the type of value whether it is int, string, float etc. 

Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes. 

We don't need to define data types in python because python is dynamically typed language, it automatically detects data types. 

Python enables us to check the type of the variable used in the program. Python provides us the type() function, which returns the type of the variable passed.

What are the basic data types in Python? What are the supported data type in Python? We are having the following inbuilt data types in Python:

Python Data types

Numbers: Represent numeral values like int, float, complex 

  1. Int :  It contains positive or negative whole numbers. eg: 1,2,3,-1.....
  2. Float : Contains real floating point representation . eg: 2.0,1.0,8.02....
  3. Complex : Numbers of form Ai+Bj . eg: 2i+3j 

x = 20     #int

print(x)

print(type(x))

x = 20.5 #float

print(x)

print(type(x))

x = 1j        #complex

print(x)

print(type(x))

20

<class 'int'>


20.5

<class 'float'>


1j

<class 'complex'> 

Sequence Type:

  • String : A string is defined as a collection of one or more characters. It is putted in single quotes or double quotes or triple quotes i.e (' ') , (" ") or (' ' '  ' ' ')  . for eg: s="GoEduHub.com"  

#String

x = "GoEduHub.com"   

print(x)

print(type(x))

GoEduHub.com

<class 'str'> 

Note – To know more about Strings, refer Python Strings

  • List : It is as same as arrays, it contains heterogeneous datatypes. eg: a=[1,2,"a"]

x = ["Go", "Edu", "Hub"]       #list

print(x)

print(type(x))

 ['Go', 'Edu', 'Hub']

<class 'list'>

Note – To know more about Lists, refer Python List.


  • Tuple :  Tuples are created by ( ) . it contains heterogeneous datatypes . eg: t=(1,2,3)

x = ("Python", "from", "GoEduHub.com")       #tuple

print(x)

print(type(x))

('Python', 'from', 'GoEduHub.com')

<class 'tuple'>

Note – To know more about Tuple, refer Python Tuple.


Dictionary: Dictionary is an unordered collection of data. It has key:value pair which  is separated by a colon :, and all keys are separated by a ‘,’. eg : d={'a':1, 'b':2, 'c':3}

x = {"name" : "anu", "age" : 36}  #dict

print(x)

print(type(x))

{'name': 'anu', 'age': 36}

<class 'dict'>

Note – To know more about Dictionary, refer Python Dictionary.


Boolean: Booleans represent one of two values: True or False.

x = True  #bool

print(x)

print(type(x))

x = b"Hello"  #bytes

print(x)

print(type(x))

True

<class 'bool'>


Set : Set is an unordered and unique collection of data types that mutable and has distinct elements. eg: s={1,2,3,4,5}

  1. Frozen set : Frozen sets are the sets that are immutable .

x = {"dl", "python", "ml"}   #set

print(x)

print(type(x))

x = frozenset({"opencv", "pandas", "numpy"}) #frozenset

print(x)

print(type(x))

{'dl', 'ml', 'python'}

<class 'set'>


frozenset({'opencv', 'numpy', 'pandas'})

<class 'frozenset'> 

Note – To know more about Sets, refer Python Set.


For more Rajasthan Technical University CSE VI Sem Python Lab Experiments Click here

3.3k questions

7.1k answers

393 comments

4.5k users

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...