Functions
- Familiar functions
output = function_name(input)
such as
result = type(3.0)
# Create variables var1 and var2
var1 = [1, 2, 3, 4]
var2 = True
# Print out type of var1
print( type(var1) )
# Print out length of var1
print (len(var1))
# Convert var2 to an integer: out2
out2=int(var2)
-
Help!
help(max) ?max
help(complex)
Help on class complex in module builtins:
class complex(object)
| complex(real[, imag]) -> complex number
|
| Create a complex number from a real part and an optional imaginary part.
| This is equivalent to (real + imag*1j) where imag defaults to 0.
-
Multiple arguments
The square brackets aroundimag
in the documentation showed us that theimag
argument is optional.
But Python also uses a different way to tell users about arguments being optional.
In sorted(iterable, key=None, reverse=False), key and reverse are optional.
# Create lists first and second
first = [11.25, 18.0, 20.0]
second = [10.75, 9.50]
# Paste together first and second: full
full = first + second
# Sort full in descending order: full_sorted
full_sorted = sorted(full,reverse=True)
# Print out full_sorted
print(full_sorted)