It's time to play with the Python!!
Starting and Running Python First we learn how to start Python and quit it cleanly.
To start Python, type python in a cmd window
or python3 in a Mac Terminal window. You will
see this, where unix> is your system prompt.
unix> python Python 3.8.5 (default, Sep 4 2020, 02:22:02) [Clang 10.0.0 ] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
To quit, type quit(). You can also use
control-D on a Mac or control-Z in windoze.
Numbers
We begin our study of the Python type ecosystem with its numerical types. There are three numerical types in Python.
intThese are arbitrary-precision integers.floatThese are 64 bit IEEE754 floating-point numbers. To see the details, see the article in Wikipedia.complexThis is a complex number type
We use the term object to refer to any datum stored in memory.
Built-in Functions You will meet lots of these. Let's learn about a couple of them.
typeThis will tell you any object's type. All objects are keenly aware of their types.absThis computes absolute value of a numeric type.printThis one has some interesting features that make ia powerful, flexible, and allows you to do what you want to do. The coding examples will show you some of its powers.
Infix Binary Arithmetic Operators Hello, Miss Wormwood!
+This adds numbers-This subtracts numbers*This is multiplication/This is division.//This is integer division.%This is "mod." Forb%a,ais divided intoband the remainder is computed.**Exponentiation
PEMDAS
The arithmetic operators have the Wormwoodean order of operations you learned in Algebra I.
Note The exponentation opearator, unlike its brethern, associates from right to left.
2**4**2 &arrr; 65536 2**4**2 = 2**16 = 65536
Relational Operators These are all familar.
<less than>greater than<=less than or equal to>=greater than or equal to==isequalto!=not equalsisequality of identity (same object)
Variables These are typeless names we stick to objects. Think this way: a variable "points" at its object.