Python Built-In Data Types
Resources: See W3 Schools Tutorials for further information.
Common Data Types
| Data type | Conversion function | Notes |
|---|---|---|
| Text | str() | |
| Integer | int() | |
| Float | float() | use e to derive a float to the power of 10 e.g. 12e2 (float is 1200.0) |
| Complex | complex() | use j for imaginary unit |
| List | list(()) | |
| Tuple | tuple(()) | |
| Set | set(()) | |
| Dictionary | dict(element1=value1, element2=value2...) | |
| Boolean | bool() | evaluate expressions, values, variables, or strings and return True or False. (Returns false for empty strings, lists, tuples, or dictionaries, and also for numbers equal to 0) |
| NoneType | assign the keyword None to a variable |
Determine Data Type
type()
Example:
name = "Ali"
print(type(name))
<class 'str'>
Example:
number = 101.2
print(type(number))
<class 'float'>
Example:
memberList = ["Ali", 17639, True] #contains string, integer, Boolean elements.
print(type(memberList))
<class 'list'>