Python For Beginner's Day - 4

Python Data Types

  • Data Types are used to define the type of the variable.

  • Python has different built-in data types,

Numeric

int, float, complex

int: holds of non-limited length (i = 5) float: holds up to 15 decimal places (i= 1.5) complex: holds complex numbers(i = 1j, j here represents the imaginary part) long: its deprecated from python3.x

String

str

str: holds sequence of characters and these are represented by either single or double quotes.

Sequence

list, tuple, range

list: holds different types of data. Like, it can hold only integers, or only strings, or both integers and strings in a list. (i = ["Hi","Friend!",5,6]) tuple: holds different types of data same as list but these are immutable. Meaning, once tuple is created it is unchangeable.(i = ("Hello!",1,2,"World!")) range: its built-in function which returns series of numbers from 0 and increase by 1 until they reach predetermined number. Utilized in for and while loops to produce series of numbers.(for i in range(1,5): )

Mapping

dict

dict: used to store data in key:value pairs and these are ordered(from Python 3.7) , changeable and do not allow dupicates.

Set

set, frozenset

set: These are mutable, used for storing multiple values in single variable, these are unordered, unchangeable(but items can be removed and can add new items) and unindexed. frozenset: These are immutable. It freeze the list and makes it unchangeable.

Boolean

bool

bool: represents True or False.

Binary

bytes, memoryview, bytearray

bytes: its an immutable sequence type to represent sequence of bytes(8-bit values). Each element in the bytes object is an integer in the range of [0,255]. Used for handling binary data such as reading/writing files, network communication or encoding/decoding data. These are defined using the b prefix the sequence of bytes enclosed in single or double quotes. (i = b'Hello!') bytearray: similar to bytes but these can be modified after creation.(i = bytearray([12,23,34])) memoryview: it is just used to create the view of memory containing binary data. It just creates the view where the data is stored. These are mainly used in high-performance applications.

NOTE : More details with examples are coming soon !!