Lab 02: Python For Programing: Variables and Operations: 2.0 Introduction (Brief Understanding On Python Terms)
Lab 02: Python For Programing: Variables and Operations: 2.0 Introduction (Brief Understanding On Python Terms)
I. Keywords: special terms in Python than cannot be used for naming variable objects
II. Operators: special tokens or elements (sequence of characters) with special mathematical or
logical meaning to the Python Interpreter.
III. Delimiters: Used in different way for statement and expression.
NOTE: Comments are import as doing a program, it serve as precursor to program documentation
>>> # Ignored by python interpreter: This python make be boring, I prefer cobra
... #
>>> X = 10 # ok that ok
>>> X2 = 20 # second value
>>> x_2 = 25 # underscore is accepted
>>> 2x = 22 # Can not start with a number
File "<stdin>", line 1
2x = 22 # Can not start with a number
^
SyntaxError: invalid syntax
>>> x-2 = 23 # This is another no no only underscore (as special character) is allowed
File "<stdin>", line 1
SyntaxError: can't assign to operator
>>> x!2 = 23 # This is another no no only underscore (as special character) is allowed
File "<stdin>", line 1
x!2 = 23 # This is another no no only underscore (as special character) is allowed
^
SyntaxError: invalid syntax
2.3 Variable Creation (with Assignment)
I. Variable is created as it is assign in a statement.
II. Creation can be in form of mathematical assignment as similar
2.5 Operators
2+4 Addition
3 -1 Subtraction
2*3 Multiplication
5/2 Quotient – integer
5 / 2.0 Division – floating point
5%2 Remainder – only apply to integer format
** Exponentiation
B. Quick on Function
#!/usr/bin/python
def findX(t):
x = 3**t
return x
y = findX(4)
print y