Data types Flashcards

(8 cards)

1
Q

Integers

A

Whole numbers.

my_number = 354

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Floating Point Numbers

A

Numbers with decimal places.
Results that end in a fraction (4 / 3) will always be a floating point number.

my_float = 3.14159

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Strings

A

A string of characters surrounded by double quotes.

my_string = “Hello”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

String Concatenation

A

Adding strings together to create a new string. This is called concatenation.

“Hello” + “Angela”
#becomes “HelloAngela

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Escaping a String

A

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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

F-Strings

A

Inserting a variable into a string by placing it between curly braces {}.

days = 365
print(f”They have are {days} in a year”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Checking Data Types

A

Check the data type by using the type() function.

n = 3.14159
type(n) #result float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Converting Data Types

A

Converting to float:
float()

Converting to int:
int()

Converting to string:
str()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly