Python Tutorial for Beginners | Data Types in Python

Fetching Comments ...
Python Tutorial for Beginners | Data Types in Python

In programming, data type is an important concept.

Variables can store data of different types, and different types can do different things.

In python, we have 14 data types and they are classified into 6 types.

I) Fundamental Categery Data Types:

1. int

Interger datatype is used to store positive or negative numeric values without decimal. This means 10 or -10 is valid int values, but 10.0 is not valid int value.

2. float

float datatype is used to store positive or negative numeric values with decimal. Which means 10.0 or -10.0 is valid float values but 10 is not valid.

3. bool

bool datatype have only 2 values True or False. True is equals to positive and False is equals to negative value.

note: ‘T’ and ‘F’ in True and False in capital are valid bool values, otherwise python will throw error.

4. complex

Complex number is represented by complex class. It is specified as (real part) + (imaginary part)j.

For example – 4+7j

II) Sequential Categery Data Types:

5. str

String datatype is used to store text values, for example name of person is a text, so datatype of this will be str, String value is represented using single quotes (”) or double quotes ("").

example

name = ‘Pawneshwer Gupta’

6. bytes

In Python, a byte string is just that: a sequence of bytes. It isn’t human-readable. Under the hood, everything must be converted to a byte string before it can be stored in a computer.

Encoding and decoding are inverse operations. Everything must be encoded before it can be written to disk, and it must be decoded before it can be read by a human.

7. bytearray

bytes and bytearray classes both hold arrays of bytes, where each byte can take on a value between 0 and 255. The primary difference is that a bytes object is immutable, meaning that once created, you cannot modify its elements. By contrast, a bytearrayobject allows you to modify its elements.

Both bytes and bytearay provide functions to encode and decode strings.

8. range

Range is used to create sequence of numbers, we can use range() function to create range.

for example

x = range(10)

this will create sequence (kind of list) from 0 to 9, which means variable x will contain 10 items from 0 to 9,

we can also define start and end as well

for example

y = range(2,8)

this will create sequence starts with 3 and ends with 7.

III) List Categery Data Types:

9. list

10. tuple

IV) Set Categery Data Types:

11. set

12. frozenset

V) Dict Categery Data Types:

13. dict

VI) None Type Categery Data Types:

14. nonetype

Share This:

Featured Posts

post preview
post preview
post preview
post preview
post preview

JOIN SOCIAL ACCOUNTS

Related Posts

Get The Best Of All Hands Delivered To Your Inbox

Subscribe to our newsletter and stay updated.