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.
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.
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.
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.
Complex number is represented by complex class. It is specified as (real part) + (imaginary part)j.
For example – 4+7j
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 ("").
name = ‘Pawneshwer Gupta’
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.
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.
bytearay provide functions to encode and decode strings.
Range is used to create sequence of numbers, we can use range() function to create range.
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
y = range(2,8)
this will create sequence starts with 3 and ends with 7.