Types, expressions, and variables Flashcards
write comments in Python
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.
int. float. str.
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.
convert int. to float.
Let’s cast integer 2 to float:
float (2)
float(2)
2.0
convert string to int.
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
Convert numbers to string
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'
Boolean
bool (1)
bool(1) bool (1) bool(1) True