-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypecasting.py
More file actions
40 lines (32 loc) · 881 Bytes
/
Copy pathTypecasting.py
File metadata and controls
40 lines (32 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#Typecast - the process of converting a variable from one type to another
# we've the functions str(), int(), float(), and bool() to help in conversations.
name = "Mike Kipruto"
age = 29
gpa = 3.2
is_student = True
#checking types
print(type(name))
print(type(age))
print(type(age))
print(type(gpa))
print(type(is_student))
# converting the gpa float to an integer
gpa = int(gpa)
print(gpa)
print(type(gpa))
# converting the age integer to a float
age = float(age)
print(age)
print(type(age))
# converting the age integer to a string
age = str(age)
print(age)
print(type(age))
# converting the name string to a boolean, for this, if the String is empty it returns a false, and a true if there is any value
name = bool(name)
print(name)
print(type(name))
# converting the is_student boolean to a string
is_student = str(is_student)
print(is_student)
print(type(is_student))