Data types Flashcards
(8 cards)
Integers
Whole numbers.
my_number = 354
Floating Point Numbers
Numbers with decimal places.
Results that end in a fraction (4 / 3) will always be a floating point number.
my_float = 3.14159
Strings
A string of characters surrounded by double quotes.
my_string = “Hello”
String Concatenation
Adding strings together to create a new string. This is called concatenation.
“Hello” + “Angela”
#becomes “HelloAngela
Escaping a String
If you want to use “” in a string, you need to escape it with a “"
speech = “She said: "Hi"”
print(speech)
#prints: She said: “Hi”
F-Strings
Inserting a variable into a string by placing it between curly braces {}.
days = 365
print(f”They have are {days} in a year”)
Checking Data Types
Check the data type by using the type() function.
n = 3.14159
type(n) #result float
Converting Data Types
Converting to float:
float()
Converting to int:
int()
Converting to string:
str()