1. Hello.
py
All we need at the end of the day is so-called text editor, a program for writing text
We just have to save it in a right format, all we need is a program for writing text,
because code is text
The bottom is terminal window, it is the command line interface to underlying
computer
It will generate a file name that ends in .py to indicate to the computer that it’s
indeed a program
2. Python Interpreter +
We need to interpret that code from top to bottom, so the computer knows what to
do
The computer only understands 0 and 1, the so-called binary system, we need to
somehow translate the code to 0 and 1 to let the computer understand it
Python is known as interpreter that you install for free, and you can run that
program, that interpreter, passing to it as input (the name of file hello.py), the
program/interpreter will handle the process of reading it top to bottom, and
translate it to 0 and 1s, so the computer can understand
3. Functions, arguments and Side Effects
Function
Every language comes from predefined functions, it is a very basic action or verbs
that the computer already know how to do that for you
Hello.py now is using 1 function
Argument
It is an input to a function that will influence the behavior of the function
Side Effect
This is the ultimate result of what the program doing on the screen
The functions can have these side effects
4. Bugs
Bugs is the mistake in the program
This one is called syntax error
5. Return values & variables
The equal sign means assignment here
We want to assign the value from right to left
6. Comments
It is just a line of note to the logic in the program
It reminds people what the intention of the program was
It can act as a pseudocode to express your thought, it helps to break the bigger
program down to the bite-sized task
We can add a comment like this
7. Multiple Function Arguments
The print function automatically insert a space for you
The + sign means concatenation.
8. Named parameters
Functions take argument, and it will influence their behavior
Everything inside in parentheses are parameters/arguments
Lets override the default value
Positional parameters
The first thing pass to print, it print that first, and the second one
Named parameters
They are optional, and you can use them by name
9. Escaping Character +
You can print the text with double quotes like this
10. F-string
We need to tell python it is a format string
11. String Method +
This is really bad problem
We can make it more compact
Strip will not take the space between the string
12. Split
13. Integers and Operations +
Run python at itself by its prompt
This is the interactive mode of python
This is the interactive mode
14. Type conversion
Readability is really important to remind us what the codes are doing
Simplicity, keep our code simple
It will increase the tactical mistake or logical error in your code
15. Float
We expect the floating point from users
Square bracket means the parameters are optional
16. Numeric Formatting +
17. Division
18. Defining function
Def is for “define”.
We can set the default value
19. Approach of using the defining function +
If you call a function, the function must exist by the time we call it
We have to define the function before we use it
But it is not logical, as we have to keep adding things at the top
The solution is we define the main part of code as “main”
Nothing will happened as no one called the function main
20. Scope +
As we define the “name” variable in the main function
We can only use the “name” variable in the main function
21. Return value