Friday, 14 April 2023

PYTHON DATA TYPES ?

 PYTHON DATA TYPES 




Today we will explain all about Python data types in this post, so let's start: -


The data that is stored in the memory of our system are of many types such as Number, Char etc. Which we call data type. There are data types in every programming language.


Thus, there are some data types in Python as well, which are as follows.

Numbers

The Python numbers data type stores numeric values.


Python 2.x had 4 built-in-data_types (int, long, float, complex). Which represents the number of data types. But in Python 3.x, by removing the long type and extending it to the int type, its length was made unlimited.


The number data type is also of three types.

int data type

float data type

complex data types

int data type:-

There is a simple numeric value in the int data type. This value is of both negative and positive types


examples:-

a= 14

print("positive int no .= ", a)

O/p:- positive int no.  = 14


b= -19

print("negative int no .= ", b)

negative int no. =   -19


Float data type

The float data type contains a decimal value. This is also of both negative and positive types.


Example :-

a= 2359.524

print("positive float no. =", a)

Output:- positive float no. = 2359.524


Complex data type:-

There are two parts to complex data types. The first real part is the second imaginary part.

Examples:-

x=10+36j

print (“complex no = ”, x)

complex no =  (10+36j)

1.) 10=real part 

2.) 36j = imaginary part


String Data Types:-

A Python string is a collection of letters or words. It works with textual data. Single (' ') or double (" ") quotations are used to enclose the string.

Python string forward indexing begins at positions 0, 1, 2, and 3. while reverse indexing begins at position -1, position -2, position -3, etc.


Examples:-

x= "hello World"

b= 'tessa parmar'

print(x)

print(b)

O/P :- hello World 

           tessa parmar


List data Types:- Python's list data type is an important one. Many values are preserved in it. A comma separates each value (,). Moreover, a square bracket is used to group all of the values ([ ])

Examples:-


 list = ['tessa parmar', "70.00"  "coding_gril_official", "P"]

print (list)


O/p ['tessa parmar', "70.00" "coding_gril_official", "P"]

Indexing of list is similar to the indexing of a string. The indexing of the list also starts from 0.

Updating list :-  You can easily update the list. Can add new value to the list. Or you can replace the old value with a new value.

Tuples:- Like lists of numerous different values separated by commas, tuples are likewise collections of values (,). Moreover, all values are maintained within brackets ( ). This data type cannot be changed. Alternatively, put cannot update tuples' values.


Example:-

tuple = ("hello", 23, 10.93,"a")

 print (tuple)

O/P:-   (‘python’, 23, 10.93, ‘a’)


Updating tuple:-

Tuples are immutable, meaning that tuples cannot be updated and their value cannot be changed.

Example :-

tuple = ("hello", 133.35, 8 ,"d",1897)

what next line comment me:-


Dictionaries;

Along with lists and tuples, dictionaries are an essential Python data type. In addition, it is a mutable data type.

It consists of key-value pairs. Each key and its corresponding value are separated by a colon (:), and each pair of keys and value is separated by a comma (,). And all the keys and values are contained within a pair of {}  curly braces

Updating Dictionaries:-

Dictionaries can be updated. In this, we can add new entries and also change the value.

Boolean data types:-

 boolean is a common data type in all programming languages. Boolean returns two values.

1. True

2. False


No comments:

Post a Comment

What is Machine learning and how to start learning?

What is Machine learning?   Innovation in computer vision, natural language processing, and speech recognition will likely be fueled by adva...