Lecture 0 - CS50P
Concepts
- Functions
- Bugs
- Variables
- Comments
- Pseudocode (伪代码,
'sju:dəʊˌkəʊd, where p is not pronounced) - Parameters and arguments.
- Params are variables can be passed;
- Args are params that are passed to a functions;
- Mostly they are the same concept.
str
+can join strings;print=print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False):printcan have many args (e.g. strings) passed;sepmeans the seperator of passed strings are;- The end of the line will add a default character
\n;` - It will be written to a special file, Standard Output;
- The buffer will not be flushed, similar to
fprintfinCwithoutfflush(stdout); 'and"are both acceptable
f"{}"format- Method
strip():str_var = str_var.strip()will remove "redundant"s (only spaces beginning and ending with, no deletion in the middle). - Method
title():str_var = str_var.title() - Methods can be used together. Just append more.
int
1+2 = 3, while"1"+"2" = "12"int(str)can transfer a text integerstrto a realint
float
- A
floatis afloat.
will returnx = float(input()) # input 999 y = float(input()) # input 1 print(f"{z:,})1,000and it is still indeed a fload. No need of999.0and1.0
def - define Functions
- No need to define the return value of function, and also for params. Just
def hello(name)rather thanint hello (char *name). - Like
C++, each param can have default value. e.g.def hello(to="world") - Scope is the extension that params function, that is one need to distinguish the difference between real parameters, form parameters, and values and know their scope of action.