Python Coding Club
Python Coding Club
Ask!
The art and science of asking questions is the source of all knowledge.
- Thomas Berger
You can find the type of a variable using type(). For example type type(x).
Casting types
Luckily Python offers us a way of converting variables to different types!
Casting – the operation of converting a variable to a different type
vs
13 49
Comparison operators
• I.e. comparison operators
• Return Boolean values
(i.e. True or False)
• Used extensively for
conditional statements
Comparison examples
False
Logical operators
• Allows us to extend the conditional logic
• Will become essential later on
Combining both
True True
Another example
These are called methods and add extra functionality to the String.
If you want to see more methods that can be applied to a string simply
type in dir('str')
Mixing up strings and numbers
Often we would need to mix up numbers and strings.
It is best to keep numbers as numbers (i.e. int or float)
and cast them to strings whenever we need them as a string.
Multiline strings
Printing
• When writing scripts, your outcomes aren't printed on the terminal.
• Thus, you must print them yourself with the print() function.
• Beware to not mix up the different type of variables!
Quick quiz
Do you see anything wrong with this block?
Another more generic way to fix it