Session 1
SCRIPTING LANGUAGES 08-10-2018 WEN-CHI YANG
Session 1 SCRIPTING LANGUAGES 08-10-2018 WEN-CHI YANG Your first - - PowerPoint PPT Presentation
Session 1 SCRIPTING LANGUAGES 08-10-2018 WEN-CHI YANG Your first program Find the file 2. Click here 3. Copy the path 1. Find the file Find the file 4. Go to the folder where your file locates by using cd Check if your file is here by using
SCRIPTING LANGUAGES 08-10-2018 WEN-CHI YANG
Check if your file is here by using ls
READ-EVALUATE-PRINT-LOOP
➢ An interactive program ➢ Useful for testing short snippets of Python code ➢ Type quit() to stop REPL
➢ Everything behind # is ignored ➢ Exercise 1
➢ Booleans : True, False ➢ Integers : …, -2, -1, 0, 1, 2, 3, … ➢ Floating-point numbers : 1.0, 0.33, -3.14159, …. ➢ Strings : “Hello world!” ➢ Exercise 2
➢ not True is False, not False is True ➢ P and Q is True only when both P and Q are True ➢ P or Q is True when either P or Q is True ➢ Exercise 3
P Q not P P and Q P or Q F F T F F F T T F T T F F F T T T F T T
➢ %s for strings ➢ %d for integers ➢ %f for floating numbers ➢\n inserts a line break, \t inserts a tab ➢ Exercise 4.1 & 4.2
➢ today = datetime.date.today() # an object ➢ today.day # an attribute ➢ today.month ➢ today.year ➢ Similar for datetime.datetime.now() ➢ exercise 5.1 & 5.2
➢ Use + to concatenate strings, e.g. “hello” + “ world!” ➢ Try to print a digit with %d, %2d and %02d ➢ Observe ➢ Exercise 6