Lecture 0 - CS50P

Concepts

  1. Functions
  2. Bugs
  3. Variables
  4. Comments
  5. Pseudocode (伪代码,'sju:dəʊˌkəʊd, where p is not pronounced)
  6. 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

  1. + can join strings;
  2. print = print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False):
    1. print can have many args (e.g. strings) passed;
    2. sep means the seperator of passed strings are ;
    3. The end of the line will add a default character \n;`
    4. It will be written to a special file, Standard Output;
    5. The buffer will not be flushed, similar to fprintf in C without fflush(stdout);
    6. ' and " are both acceptable
  3. f"{}" format
  4. Method strip(): str_var = str_var.strip() will remove "redundant" s (only spaces beginning and ending with, no deletion in the middle).
  5. Method title(): str_var = str_var.title()
  6. Methods can be used together. Just append more.

int

  1. 1+2 = 3, while "1"+"2" = "12"
  2. int(str) can transfer a text integer str to a real int

float

  1. A float is a float.
    x = float(input())  # input 999
    y = float(input())  # input 1
    print(f"{z:,})
    
    will return 1,000 and it is still indeed a fload. No need of 999.0 and 1.0

def - define Functions

  1. No need to define the return value of function, and also for params. Just def hello(name) rather than int hello (char *name).
  2. Like C++, each param can have default value. e.g. def hello(to="world")
  3. 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.