Changes between Version 115 and Version 116 of ControlSystems/SoftwareTeam/IntroToPython
- Timestamp:
- Sep 4, 2017, 11:42:10 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/IntroToPython
v115 v116 16 16 Python, like every programming language, has a structure. Here are the big parts: 17 17 18 * ''Variables'': Things you assign to and read from. Like in Algebra. `a="Dump Truck"` sets the variable Ato the string "Dump Truck". You can set them to numbers to or fancy things like lists. They're basically the nouns.18 * ''Variables'': Things you assign to and read from. Like in Algebra. `a="Dump Truck"` sets the variable `a` to the string "Dump Truck". You can set them to numbers to or fancy things like lists. They're basically the nouns. 19 19 * ''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. 20 20 * ''Functions'': These do things. They take nouns as arguments, do something, and can return 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. … … 45 45 Hello World! 46 46 }}} 47 The program told the computer to print the value of variable a on the screen.47 The program told the computer to print the value of variable `a` on the screen. Its considered a best practice to name your variables as nouns. 48 48 49 49 And, boom, now you're a programmer. The rest of learning how to code is just more details. This is the end of Lesson 1. … … 265 265 Run this one. What does it output? A lovely happy birthday song for two kids? Now imagine if you had to write a program to print out a happy birthday for every single person in your grade without it. It'd get pretty ugly, fast. 266 266 267 The keyword `def` is used in Python to indicate a custom function, and you have to ''def''ine it in your program before you use it. This function takes an argument of an age, and second argument of a list of names. The "singHappyBirthday" line at the end actually ''calls'' or runs the custom function, with the two arguments it needs. 267 The keyword `def` is used in Python to indicate a custom function, and you have to ''def''ine it in your program before you use it. This function takes an argument of an age, and second argument of a list of names. The "singHappyBirthday" line at the end actually ''calls'' or runs the custom function, with the two arguments it needs. Its considered a best practice to name your functions as verb phrases. 268 268 269 269 A function can return a value too, by using the Python keyword `return` for example: