Datatypes
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default
- Text Type:str
- Numeric Types:int, float, complex
- Sequence Typeslist, tuple, range
- MappingType:dict
- Procedure and object oriented
- Huge Library
- Scalable
Numeric Types
- int: Positive or negative whole numbers.
- float: Any real number with a floating-point representation in which a fractional component is denoted by a decimal symbol or scientific notation.
- complex:A number with a real and imaginary component represented as x+2y.
- bool:Data with one of two built-in values True or False. Notice that 'T' and 'F' are capital. true and false are not valid booleans and Python will throw an error for them.
- none:The None represents the null object in Python. A None is returned by functions that don't explicitly return a value
Sequence Type
A sequence is an ordered collection of similar or different data types. Python has the following built-in sequence data types.
- String:A string value is a collection of one or more characters put in single,double or triple quotes.
- List:A list object is an ordered collection of one or more data items, not necessarily of the same type, put in square brackets.
- Tuple:A Tuple object is an ordered collection of one or more data items, not necessarily of the same type, put in the parentheses.
Mapping Type
Dictionary: A dictionary dict() object is an unordered collection of data in a key:value pair form. A collection of such pairs is enclosed in curly brackets. For example:{1:"Madhu",
2:"Kumar", 3:"Ram",4:"Sohan"
Set Types
- Set:Set is mutable, unordered collection of distinct hashable objects. The set is a Python implementation of the set in Mathematics.
- frozenset:Frozenset is immutable version of set whose elements are added from other iterables.
Mutable and Immutable types
Data objects of the above types are stored in a computer's memory for processing. Some of these values can be modified during processing, but contents of others can't be altered once they are created in the memory.