0% found this document useful (0 votes)
157 views

MIT Python Week 1 Notes

This document summarizes key concepts in Python including: 1. Python uses the IDLE text editor and >>> prompt to run code and evaluate expressions. Basic operators include +, -, *, /, **, //, and %. 2. Variables store memory addresses that refer to and point to values. Variables are assigned values using the = operator. 3. Functions are defined using def and can take arguments. Function calls evaluate arguments and pass them to the function. The return statement passes back a returned value.

Uploaded by

nathana_3
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views

MIT Python Week 1 Notes

This document summarizes key concepts in Python including: 1. Python uses the IDLE text editor and >>> prompt to run code and evaluate expressions. Basic operators include +, -, *, /, **, //, and %. 2. Variables store memory addresses that refer to and point to values. Variables are assigned values using the = operator. 3. Functions are defined using def and can take arguments. Function calls evaluate arguments and pass them to the function. The return statement passes back a returned value.

Uploaded by

nathana_3
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 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 =.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy