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

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

Popular posts from this blog

Conditional Statements

6.00.1x - Week 2

Basic Machine Architecture