Title | Python Review Notes |
---|---|
Author | chaa-san |
Course | Computer programming |
Institution | Seneca College |
Pages | 4 |
File Size | 123.4 KB |
File Type | |
Total Downloads | 58 |
Total Views | 160 |
A simple review of the functions in python. It has basic definitions as well as some of the advance functions...
Variable - can assign any data and can name anything What you can assign a variable: Data Types Integers: a whole number (ex. 1 or -5) Float: a “decimal” number (ex. 4.3 or 2.2222222…) much flexible Boolean: a value of either True or False. Can be put in a variable String: a “string” of any numbers or characters as denoted (‘ ’ or “ “) ex. “Hello World” or “:)” note - you can turn integers or floats into strings via the syntax: str(x) (https://www.programiz.com/python-programming/keyword-list) Keywords: these are reserved by python so it can follow your instructions. It’s functionality does not change. For example: - True, False - None - Break (used in while loops), pass - import - class - def - if, elif, else - while - for - in - not (negate), or, ands - return Function: built in functions, ie, print, something python recognizes that has arguments inside its brackets. Arguments: anything contained in a function's brackets. List of variable you define in your function definition function call - calling on that function to do something. Print v.s Return print - a function that will take whatever string is in its brackets and print it in to the terminal return - will return a value, gives a value later on and can be used outside your function You can have nested if statements. if and elif can have a condition after them but not in else Operators - uses to manipulate or check data Boolean Comparisons: and, or, not (https://www.programiz.com/python-programming/operators) Arithmetic operators
Operator
Meaning
Example
+
Add two operands
x+y+2
-
Subtract right operand from left
x - y -2
*
Multiply two operands
x*y
/
Divide left operand by the right one (always results into float)
x/y
%
Modulus - remainder of the division of left operand by the right
x % y (remainder of x/y) 10 % 3 → 3*3+1 → 1
//
Floor division - division that results into whole numbers adjusted to the left in the number line
x // y 5 // 2 → 2.5 → 2
**
Exponent - left operand raised to the power of right
x ** y (x to the power of y)
Operator
Meaning
Example
>
Greater than - True if left operand is greater than the right
x>y
<
Less tha - True if left operand is less than the right
x=
Greater than or equal to - True if left operand is greater than or equal to the right
x >= y...