Intro to Python for Data Science Learning 3 - functions

Functions

from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-functions-and-packages?ex=1

  • 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 around imag in the documentation showed us that the imag 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)

上一篇:spring cloud之eureka简介


下一篇:RabbitMQ服务端配置详解