Python Programming 2
Python Programming 2
COLLEGE
Established 1982
• Debugger
Coquitlam College CSCI120 3
Python
Syntax, Keywords
• Syntax
– High-level languages have strict rules how to built structurally correct
programs.
– Syntax rules
• Syntax Errors
– not obeying the syntax rules
• Keywords in Python
– reserved words with a specific meaning in Python
– cannot be used as variable names, function names, or any other
identifiers
– here is the complete list of keywords
• Example
# Demo output in Python
# Author: Rita Ester
# Date: 21-08-2019
• Line starts with #
• Why comments?
– for documentation of a program
– give explanations
• Numeric expressions
• Python evaluates an expression.
• Examples of mathematical expressions
– 3+4
– 3*4
– 21 + 3*7
– (3+5) * (2/0.5)
• Structure of an expression 3576.78 + 4000
Multiplication * 2*3 == 6
Division / 14 / 3 ==
4.666666666666
Integer Division // 14 // 3 == 4
(floor division)
Remainder (modulus) % 14 % 3 == 2
Addition + 1 + 2 == 3
Subtraction - 4 - 3 == 1
Coquitlam College CSCI120 8
Mathematical Expressions
• What is a string?
– the way to represent plain text.
– "Hello World" enclosed in double quotation marks
– 'Hello World' enclosed in single quotation marks
• String concatenation
– "Hello " + "World"
– print("Hello " + "World"), displays: Hello World
• String multiplication
– 3 * "Hello "
– print(3*"Hello "), displays: Hello Hello Hello