May 17, 2024
Lecturer: Siddharthan
This lecture focuses on the basic data types in Python, the second module of a hands-on machine learning course with Python. This is the third video in this module.
The five basic data types in Python are:
int
)float
)complex
)bool
)str
)a = 8
type(a)
-> int
print(a)
-> 8
b = 2.3
type(b)
-> float
print(b)
-> 2.3
c = 1 + 3j
(here 1
is real, 3j
is imaginary)type(c)
-> complex
print(c)
-> 1+3j
x = 10
y = float(x)
Results:
print(y)
-> 10.0
type(y)
-> float
x = 5.88
y = int(x)
Results:
print(y)
-> 5
(removes decimal, does not round)type(y)
-> int
True
or False
.a = True
b = False
Check the data type: type(a)
-> bool
a = 7 > 3
print(a)
-> True
type(a)
-> bool
my_string = "Machine Learning"
type(my_string)
-> str
print(my_string)
-> Machine Learning
print("Hello" * 5)
Results: HelloHelloHelloHelloHello
s = "Programming"
print(s[0:5]) # Output: 'Progr'
s = "Programming"
print(s[0:10:2]) # Output: 'Pormn'
word1 = "Machine"
word2 = "Learning"
print(word1 + " " + word2)
Results: Machine Learning