-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy path02_datatypes.py
More file actions
34 lines (26 loc) · 851 Bytes
/
02_datatypes.py
File metadata and controls
34 lines (26 loc) · 851 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
"""
Python is a strongly-typed language under the hood, which means
that the types of values matter, especially when we're trying
to perform operations on them.
Note that if you try running the following code without making any
changes, you'll get a TypeError saying you can't perform an operation
on a string and an integer.
"""
# * SOLUTIONS BELOW:
# * OPEN INTERPRETER && RUN: python3 02_datatypes.py
# ? TYPE() - RETURNS THE TYPE OF VALUE YOU ARE DEALING WITH.
# ? EX: <class 'int'> || <class 'str'>
x = 5
y = "7"
# Write a print statement that combines x + y into the integer value 12
# ? INT() - CONVERTS A VALUE TO INTEGERS
print(
x + int(y),
type(x + int(y))
)
# Write a print statement that combines x + y into the string value 57
# ? STR() - CONVERTS A VALUE TO STRING
print(
str(x + int(y)),
type(str(x + int(y)))
)