Datatypes in python:

 Datatypes in python:

Data type: datatype is something that represents the type of data.

ex: name=“Zaheer”

Here name is a variable and Zaheer is a string.

There are different types of data types are there, they are :

numbers
String
List
Tuples
Dictionary
Boolean
sets

-Numbers: it consists of - integers ( ex. 1,2,3,4 )

- floats(ex. Decimal numbers 1.2, 2.000)

- complex numbers (a combination of real and Imaginary( ex. 2+4i )

-Strings: is a collection of characters(mystr1=“Zaheer”)

-List: is a group of values inside  square brackets [ ]
ex: [ ‘a’, 10,  7.12, ”data”]

-tuples:  a group of values within brackets ( )
my group = (  ‘a’, ’b’, ’c’, )

-Dictionary: a group of values within curly braces { }
ex: mydictionary = {1: ‘john’ , 2: ‘bob’ }
1:’john’ was 1 is a key and john is a value here two elements are required to define the elements in a dictionary key and value

-Sets: an unordered collection of items within { } and we don’t need to define key values in it. It is basically an unordered collection of items
ex:  myset = {1,2,3}

-Boolean: it consists of true and false where In c and c++  0 and 1 is used for Boolean
- 0 represents “false”
- 1 represents “true”

A small comparison 

in c language :

in c language to add numbers we have


int a ; /* declaration */

a=5;  /* initialization*/

int a, b, c ; 
a = 5
c = a + b


wherein python :

were in python  a =5 
b = 6
c = a+b
here is no declaration part inpython

It automatically includes initialization and declaration So there is no specific data type to declare a variable. here  ‘a’ is a variable to store numeric data ‘5’. ‘b’ is a variable to store numeric data ‘6’. 




No comments:

Post a Comment