Video 3 : Primary Data Types in Python
Simply put, it is the nature of the information.
These are the primary data types available in python
= 1 # Integer. Stores integers
i = 5.78 # Floats. Stores numbers with decimal parts.
r = 'h' # Characters. Stores single characters. It is a string in python!
c = 'Strings' # Strings. Stores a series of characters
s = True/False # Logical. Stores binary values
l = 6.0+5.6j # Complex. Stores complex values cm
Strings are long chain of letters, numbers, symbols, and special characters. You can use both single and double quotes, but must end accordingly. Use slash to place quotes if needed.
In python, there is no equivalent for char
type.
"Hello",
'Hello',
'My name is Arun',
"I asked, 'what is for lunch?'"
'I exclaimed, "This tree is big!"'
"I used slash \" to type a double quote symbol"
= 1.5 # Float/Real
a print(a, id(a), type(a))
= "hello" # String/Character
a print(a, id(a), type(a))
= 5 # Integer
a print(a, id(a), type(a))
= True # Logical
a print(a, id(a), type(a))
= 6.0+7.8j # Complex
a print(a, id(a), type(a))
= [7, 8.9, 10] # List
a print(a, id(a), type(a))
= (5.2, 4, 12) # Tuple
a print(a, id(a), type(a))
= {'v1': 6, 'v2' : 10} # Dictionary
a print(a, id(a), type(a))
# Get the ASCII/unicode value of a character
print(ord('z'))
# Get the character for the ASCII/unicode
print(chr(98))
print(chr(32250))
1.5 140048331680624 <class 'float'>
hello 140048284573232 <class 'str'>
5 140048501217856 <class 'int'>
True 140048500811040 <class 'bool'>
(6+7.8j) 140048284294832 <class 'complex'>
[7, 8.9, 10] 140048284073544 <class 'list'>
(5.2, 4, 12) 140048284133416 <class 'tuple'>
{'v1': 6, 'v2': 10} 140048284066872 <class 'dict'>
122
b
緺
id()
: returns the memory location ID of the variable.type()
- returns the datatype of the variable.ord()
- returns the ASCII/Unicode value of the symbol.chr()
- returns the symbol of the ASCII/Unicode value.