Home / Computer Science / Python / 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.

Variables,Data types in Python 1

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 Santosh Kumar Gadagamma

I'm Santosh Gadagamma, an Experienced Software Engineer passionate about sharing knowledge in technologies like Java, C/C++, DBMS/RDBMS, Bootstrap, Big Data, Javascript, Android, Spring, Hibernate, Struts, and all levels of software design, development, deployment, and maintenance. I believe computers are essential for the world's functioning, and I'm committed to helping others learn the skills they need to succeed in tech. My website is a valuable learning tool to help you reach greater heights in your education and career, and I believe that education has no end points.

Check Also

Interview Questions for Python Strings

Unleashing the Power of Python Strings: Advanced Methods for String Manipulation

In this blog post, we will explore advanced methods for python strings that expand your …