7 February 2022

Q1 This is on five minutes before class begins. Start it when you arrive.

Last Time We learned about the basic scalar types in Python: numbers (int, float, complex), booleans, and strings.

If you like Wordle, this is Required Viewing

Casting

picture of iron being cast

A cast is a temporary request to regard an object of one type as being of another. Be warned: not all casts make sense. Make a bad one and Python will throw an error, resulting in program death. Note, in the table below, everything casts to a string.

from/tointfloatboolstr
int*"obvious" unless the integer is too bigFalse if 0, True otherwisenumerical string
floattruncates fractional part*False if 0, True otherwisenumerical string
bool1 for True and 0 for False1 for True and 0 for False*boolean string
strthe value given, if the string is a parseable integer the value given, if the string is a parseable float if the string is empty, False, True otherwise *

How do I find out ... ?

Python Documentation Here are links to some useful pages that will help you learn Python.

String Varieties

Special Characters

Format Strings

Raw Strings

Triple-Quoted Strings

Make us!

*
**
***
****
*****


    *
   ***
  *****
 *******
*********
     *
    * *
   * * *
  * * * *
 * * * * *
* * * * * *
    * *
    * *

Using input