Sunteți pe pagina 1din 3

Python As A Calculator

shell - text editor window of IDLE prompt - (>>>) Python instructions are typed next to it and when we press enter Python will evaluate those instructions. Operator Symbol addition + subtraction multiplication * exponentiation ** division / integer division // modulo (remainder) % Two of Python's numeric types int: integer float: floating point number an approximation to a real number Operator Precedence ** highest precedence -(negation) * / // % + lowest precedence syntax - rules governing what is and isn't legal in a programming language; specifies which combination of symbols are legal. * an open parenthesis covers more than one line until a closing parenthesis is placed semantic error - occurs when the meaning of a particular expression is invalid. ex. 4 / 0 -------------------------memory address - specifies the individual location inside the computers memory numerically ex- x203 variable - a named location in computer memory. Python keeps track of variables in a different location than values. Terminology - A value HAS a memory address. - A variable CONTAINS a memory address. - A variable REFERS TO a value. - A variable POINTS TO a value. Examples of use Value 8.5 has memory address x34. Variable shoe_size contains memory address x34.

The value of shoe_size is 8.5. shoe_size refers to value 8.5. shoe_size points to value 8.5. ---------------------assignment statements - using a variable to assign an expression; variable = expression ex. a =8 Rules for executing an assignment statement 1. Evaluate the expression on the right side of the = sign to produce a value. This value has a memory address. 2. Store the memory address of the value in the variable on the left side of the =. Rules for legal Python names 1. Names must start with a letter or_. 2. Names must contain only letters, digits, and _. When not following these rules the editor will produce a syntax error. Python naming convention In Python most variable names use lower case letters with under scores to separate words, we call this pothole_case. Use pothole_case in most situations so that other Python programmers have an easier time reading your code. -------------------------------argument - an expression that appears between the parentheses of a function call to pass - the action of providing an argument to a function Function call - statement that asks Python to evaluate a function. Form of Function Call - name of the function, an open parenthesis, comma separated list of expressions known as arguments, and a closing parenthesis function_name(arguments)\ Rules for executing a function call 1. Evaluates each argument one at a time, working from left to right 2. Calls the function, passing in the argument values dir(__builtins__) - a built in function that shows up all other built in function in Python help(insert built in function name) - built in function that shows a description of the built in function which is placed in parentheses In help documentation, square brackets around variables indicates arguments that are optional.

----------------------------def - a keyword indicating a function definition parameter - a variable that appears between the parentheses of a function definition. Parameters get their values from expressions in a function call. Return statement return followed by an expression Rules for executing a return statement 1. Evaluates the expression, which produces a memory address 2. Passes back the memory address to the call Function definition def functionname(paramtres): body Function calls are expressions. Rules for executing an assignment statement 1. Evaluate the expression on the right of the = sign to produce a value 2. Store the memory address of the value in the variable on the left of the =.

S-ar putea să vă placă și