Data Types - Python
Basic
- Variable/Identifier => Container that holds Data
varName = value
=> Enter a value
varName = "value"
=> String variable
global varName = value
=> Turn local variable into a global variable
- Value/Literal
- Double Typecasting is not possible at once
type(varName)
=> Returns type of variable
Data Types
- Built-in
- Numeric
- int => Integer
- float => Decimal Number
- complex
varName = complex(N1, N2)
=> Declare a complex
- Text
- str
varName = "value"
=> Declare a string
- Boolean
varName = True
=> Declare a boolean
varName = False
- Sequence
- list
- Mutable, Ordered
varName = [N1, "value1", varName1]
=> Declare a list
varName = [N1, [N2, N3]]
- tuple
- Ordered, Immutable List
varName = (N1, "value1", varName1)
=> Declare a tuple
- set
- Unordered, Immutable, No Duplicates
varName = {N1, "value1", varName1}
=> Declare a set
- Map
- dict
- Unordered, Key-Value pair, No duplicate Keys
varName = {"key1": "value1", "key2": N1}
=> Declare a dictionary
- User-defined
Typecasting
- Types
- Explicit
- Implicit => Lower order data type automatically converted into higher order
- Methods
int()
float()
str()
ord()
hex()
oct()
tuple()
set()
list()
dict()