Summary: Python
- This + 400k other summaries
- A unique study and practice tool
- Never study anything twice again
- Get the grades you hope for
- 100% sure, 100% understanding
Read the summary and the most important questions on Python
-
Tutorial A1 Numeric
This is a preview. There are 8 more flashcards available for chapter 04/09/2016
Show more cards here -
Python has the standard types (4)
int,
float,
long,
complex -
'Arithmetic' operators: floor division(//) en remainder(%)
a // b is the largest multiple of 1 (or 1.0) equal to or below a / b
remainder with division: a % b = (a / b – a // b) * b
voorbeeld: 10//4 = 2 met remainder ((2.5-2)*4)=2 -
'Arithmetic' operators: exponentiation (**)
standard arithmetic “to the power”: a ** b is “a to the power b” -
'Arithmetic' operators: unary minus(-) and unary plus(+)
negative (with only an operand to the right): –a = 0 – a
positive (with only an operand to the right): +a = 0 + a -
'Arithmetic' operators: bitwise and (&)bitwise or (|)bitwise xor (^)
low level operation on int and long
Bitwise XOR sets the bits in the result to 1 if either, but not both, of the corresponding bits in the two operands is 1.
Example 1
>>> bin(0b1111 ^ 0b1111) '0b0' >>> bin(0b1111 ^ 0b0000) '0b1111' >>> bin(0b0000 ^ 0b1111) '0b1111' >>> bin(0b1010 ^ 0b1111) '0b101' -
for importing module math type:
import math -
Tutorial A2 String
This is a preview. There are 12 more flashcards available for chapter 05/09/2016
Show more cards here -
String (voorbeeld lower, upper , count en varabele toewijzen)
low = s.lower() -> ('some mixed case string')
low.count('e') == 3
up = s.upper() -> ('SOME MIXED CASE STRING')
up.count('e') == 3 -
Tutorial A3 def function
This is a preview. There are 3 more flashcards available for chapter 06/09/2016
Show more cards here -
opbouw functie (function heading en function body)
The first line is called the function heading; the rest of the function is the function body. The function heading begins with the keyword “def” and ends with a colon (“:”). It states the name of the function and, within parentheses, the parameters.
Inside the function body, the names of the parameters can be used like variables that have been assigned some value.
def area_rectangle (x_lo, x_hi, y_lo, y_hi):
width = x_hi - x_lo
height = y_hi - y_lo
area = width * height
return area -
defineren en oproepen functie
def area_rectangle(x_lo, x_hi, y_lo, y_hi):
width = x_hi - x_lo
height = y_hi - y_lo
area = width * height
return area
oproepen functie met gewenste waarde zier er zo uit:
area_rectangle(3, 7, 2, 8) -
It is bad practice as well to let a function do a computation and print the result as well.
The result cannot be used in any other way when it has been printed only!
(Printing and returning as well is even worse – don’t do it.)
- Higher grades + faster learning
- Never study anything twice
- 100% sure, 100% understanding