Written by Joseph Lee
ee
|L
on
th
Py
, 1
NOTICES..............................................................................................................................................................3
CodeSnipping.................................................................................................................................................3
InstallingPython.................................................................................................................................................4
Step1:Downloadingpython...........................................................................................................................4
Step2:DownloadinganIDE...........................................................................................................................4
PythonFundamentals.........................................................................................................................................5
DataTypes....................................................................................................................................................................5
ee
Strings......................................................................................................................................................................5
Integers...................................................................................................................................................................5
Floats.........................................................................................................................................................................5
Booleans.................................................................................................................................................................5
BasicMathematicalOperations................................................................................................................6
|L
ComparisonOperators........................................................................................................................6
LogicGates.....................................................................................................................................................7
AND...........................................................................................................................................................7
OR.............................................................................................................................................................7
NOT...........................................................................................................................................................8
DataStructures/Containers................................................................................................................................8
PythonSyntaxI.................................................................................................................................................10
on
FundamentalRules.......................................................................................................................................10
Declaration&Definition...........................................................................................................................10
Declaration........................................................................................................................................10
Example1:...................................................................................................................................10
Example2:...................................................................................................................................10
th
Definition............................................................................................................................................10
Example1:...................................................................................................................................10
Example2:...................................................................................................................................11
Indentation...............................................................................................................................................11
Example1:.........................................................................................................................................11
Py
Example2:.........................................................................................................................................12
Colons.....................................................................................................................................................12
Example1:.........................................................................................................................................12
Example2:.........................................................................................................................................12
If,elif,andelsestatements............................................................................................................................13
ifstatements............................................................................................................................................13
elifstatements.........................................................................................................................................13
elsestatements.......................................................................................................................................13
Whileloopsandforloops..............................................................................................................................15
Whileloops..............................................................................................................................................15
Terminating loop...............................................................................................................................15
, 2
Infinite/Foreverloop...........................................................................................................................15
Forloops.................................................................................................................................................15
PythonSyntaxII................................................................................................................................................16
ModulesandLibraries...................................................................................................................................16
Import,From,andAs...............................................................................................................................16
Import................................................................................................................................................16
From..................................................................................................................................................16
As......................................................................................................................................................17
ee
BasicModules.........................................................................................................................................17
CallingFunctions...............................................................................................................................17
Example1:...................................................................................................................................17
Example2:...................................................................................................................................17
Example3:...................................................................................................................................17
|L
Functions....................................................................................................................................................................18
Voidfunctions&ValueReturningfunctions.............................................................................................18
Creatingfunctions...................................................................................................................................18
FunctionCalls..........................................................................................................................................18
FunctionVocabulary................................................................................................................................19
PythonSyntaxIII...............................................................................................................................................20
Try,Except,Finally........................................................................................................................................20
on
Try...........................................................................................................................................................20
Except.....................................................................................................................................................20
Example1:.........................................................................................................................................20
Example2:.........................................................................................................................................21
Finally......................................................................................................................................................21
th
Example1:.........................................................................................................................................21
Open,andWith.............................................................................................................................................22
Open........................................................................................................................................................22
With.........................................................................................................................................................22
ExampleFile:.....................................................................................................................................23
Py
Example1:.........................................................................................................................................23
Example2A:......................................................................................................................................23
Example2B:......................................................................................................................................24
Example3:.........................................................................................................................................24
ModulesandLibraries......................................................................................................................................24
TurtleGraphics..............................................................................................................................................24
Basics......................................................................................................................................................25
ImportingTurtle..................................................................................................................................25
CreatingTheTurtleObject................................................................................................................25
BasicMovement................................................................................................................................25
PenControl........................................................................................................................................25