Variables, Expression and Assignment Statements
Variable naming rule and convention:
- Can not start with a digit
- Uppercase and lowercase letters
- Digits
- Underscore '_'
- By convention, variable names are lowercase, separated by _
- Variable names are case sensitive
List of identifiers and reserved keywords: https://docs.python.org/3/reference/lexical_analysis.html#identifiers
Note above, since "area" was calculated before size change its value, area still 9 even though size is now 5
Syntax vs Semantic Errors:
Above shows difference between syntax and semantic errors, though I really like this explanation.
Expression vs Assignment Statement:
- Expression: evaluate, return/yield value/result
- Assignment: change state of variable/computaion and Python shell doesn't return anything
Note:
zipcode = '15245'
zipcode + 3, Error because we can't add a type str and a type int
zipcode * 3 will return 3 copies of zipcode, ie '152451524515245'
z == (x * y) + 100 is an Expression, not a Assignment statement
Comments
Post a Comment