Changes between Version 144 and Version 145 of ControlSystems/SoftwareTeam/IntroToPython
- Timestamp:
- Sep 5, 2017, 8:09:33 AM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/IntroToPython
v144 v145 18 18 Python, like every programming language, has a structure. Here are the big parts: 19 19 20 * ''Variables'': [[Image(https://mdn.mozillademos.org/files/13506/boxes.png,10%,right,nolink)]] Things you assign to and read from. Like in Algebra. `a="Dump Truck"` sets the variable `a` to the string "Dump Truck" (a string is just a sequence of letters and numbers strung together...hence the name). You can set them to strings/text, numbers or fancy things like lists. They're basically the nouns. You can think of a variable as a box you can store something in.20 * ''Variables'': [[Image(https://mdn.mozillademos.org/files/13506/boxes.png,10%,right,nolink)]] Things you assign to and read from. Like in Algebra. `a="Dump Truck"` sets the variable `a` to the string "Dump Truck" (a string is just a sequence of letters and numbers strung together...hence the name). You can set them to strings/text, numbers or fancy things like lists. They're basically the nouns. You can think of variables as boxes you can store things in; you give each box a name like "student" for the box you'll store student names in or "isaMentor" for the box you'll store whether someone is a mentor (true/false) or "age" where you might store their age in years. 21 21 * ''Control Structures'': These are core programming language instructions like IF this is true THEN do that…. These are a lot like grammar rules, like: use active voice, or use punctuation. They're how you get stuff done. Control structures can let you do things selectively (conditionally), iteratively (repeatedly), and sequentially. 22 22 * ''Functions'': [[Image(https://upload.wikimedia.org/wikipedia/commons/thumb/3/3b/Function_machine2.svg/220px-Function_machine2.svg.png,right,8%,nolink)]]These do things. They take nouns as arguments (inputs), do something, and can return (output) nouns. In `redCar = paintCarRed(blueCar)`, `paintCarRed` is a function. They're the verbs, they do things, and they take variables and return variables. Many functions are built in to Python, but you can (and should) create your own. The ability to create your own functions (new words!) is a big part of what makes programming languages so powerful.