Types, expressions, and variables Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

write comments in Python

A

To write comments in Python, use the number symbol # before writing your comment. When you run your code, Python will ignore everything past the # on a given line.

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

int. float. str.

A

ou can get Python to tell you the type of an expression by using the built-in type() function. You’ll notice that Python refers to integers as int, floats as float, and character strings as str.

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

convert int. to float.

A

Let’s cast integer 2 to float:

float (2)

float(2)
2.0

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

convert string to int.

A

Sometimes, we can have a string that contains a number within it. If this is the case, we can cast that string that represents a number into an integer using int():

int (‘1’)

int(‘1’)
1

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

Convert numbers to string

A

If we can convert strings to numbers, it is only natural to assume that we can convert numbers to strings, right?

str (1)
​
str(1)
​
'1'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Boolean

A

bool (1)

bool(1)
bool (1)
​
bool(1)
True
How well did you know this?
1
Not at all
2
3
4
5
Perfectly