Home / Posts / Variables,Data types in Python

Variables,Data types in Python

Like other programming languages python has standard data types, those are

  1. Numbers
  2. Strings
  3. List
  4. Tuple
  5. Dictionary

In python, there is no explicit declaration of variables. As we know a variable is a reserved memory location to store specified data values. When a variable is created it reserves a space in memory with the memory name as a variable. As per the data type assigned data to the variable memory space is resereved and what is stored in that memory space.

Generally in C or Java etc languages an intereger variable can be declared as

  int A =10;

Variable A is of integer type and value is 10.

But, in python the variable is declared as

   A = 10;

Python interepreter automatically treated a is a variable of integer type based on the assigned value of that variable.

A = 10 // A is integer type

B = 10.25 // B is floating type

C =’a’ // C is character type

D = “String” //D is of type String

In  python,  single quote and double quotes are used for declaring string or characters.  Anything between single or double quotes can be treated as  data type String.

To know the data type of variable in python  use type().

Syntax : type(variable)

Print(type(A)) -> it prints  A is of type integer.

See the above image for variable declaration and its type.

>>> A = 10
>>> B = 10.25
>>> C = 'a'
>>> D = "String"
>>> print(A)
10
>>> print(type(A))
<class 'int'>
>>> print(B)
10.25
>>> print(type(B))
<class 'float'>
>>> print(C)
a
>>> print(type(C))
<class 'str'>
>>> print(D)
String
>>> print(type(D))
<class 'str'>
>>> 

About GSK

Hi, i am Santosh Gadagamma, a tutor in Software Engineering and an enthusiast for sharing knowledge in Computer Science and other domains. I developed this site to share knowledge to all the aspirants of technologies like, Java, C/C++, DBMS/RDBMS, Bootstrap, Big Data, Javascript, Android, Spring, Hibernate, Struts and all levels of software project design, development, deployment, and maintenance. As a programmer I believe that, "The world now needs computers to function." Hope, this site guides you as a learning tool towards greater heights. I believe that Education has no end points and i wish to learn more in the process of teaching you.

Check Also

Design your Logo

Logo Maker Design your organization or firm or company logo by following simple steps.