O GoConqr está de visual novo! Conte para nós o que você achou.

Flashcards

python function characteristics

Andrew Sperazza python Inglês 29 flashcards

Flashcards do conjunto (29)

  1. 1what can functions be 'generalized' as ?as "callable" (ie via __callable__)
  2. 2how can you make callable objects from instances?implement __call__()
    method
  3. 3what are 2 flavors of arguments to a function?positional and keyword
  4. 4what is the difference between keyword argument and positional argument?keywords use 'keyword and value' as in arg2=1.618
  5. 5can keyword arguments come before positional arguments?no, keyword arguments come after positional
    func(arg1, arg3=1.4)
  6. 6what about ordering of keyword args?keyword args can be in ANY order provided they all follow any positional arguments
  7. 7how many times is default value evaluated if a function is called 3 times?it is only evaluted 1 time, first time.
  8. 8how can you make a class runnable?you can make a class callable by implementing
    __call__(self,arg):
    function
  9. 9how would you represent : if condition: ` result=true_value ` else : ` result= false_value ` using a conditional expression?result=true_val if condition else false_val
  10. 10what useful function can sort a string of fname and lname, based on lastnamesortable(iterable, key=None, reverse=False) --> new sorted list
  11. 11example of sorting list using sorted function: scientists=['mar cur', 'al eins', 'niels bor']sorted( scientists,
    key=lambda name: name.split() [-1])
  12. 12how would you extract last name from x="nikola tesla" using lamdas?last_name=lambda ln: ln.split()[-1]
    then callit : last_name(x)
  13. 13difference between function and lambdamethod call is a STATEMENT that defines a function and bind it to a name.
    lambda is an EXPRESSION that evaluates to a function
  14. 14can lambdas have name?no, lambdas are anonymous
  15. 15how are arguments supplied to lambda?argument list is separated by commas, terminated by colon
  16. 16how do you represent empthy () arguments to a lambda ?zero arguments=>
    lambda:
  17. 17what is the block of a lambda?the block of a lambda is a 'single expression'
  18. 18how do represent the return value for a lambda?the return value for a lambda is given by the BODY of the EXPRESSION. return statement is not allowed.
  19. 19can lambdas use docstrings?no
  20. 20how can you test lambda?awkward or impossible, keep it simple
  21. 21how can you tell if object is callable?use callable(func_name)
    returns T / F
  22. 22how can you handle various sizes of arguments passed in?use func(*args)
  23. 23how to determing number of arguments passed in to *argsi=iter(args)
    v=next(i)
    or better:
    func(arg1, *args)
    len=arg1
    for item in args
  24. 24how would you construct func parameters for following call: func('headername', src1="data1", src2="data2")func(hname, **kwargs)
    ==> gives you one string and one dictionary
    hname=headername
    kwargs={src1:"data1", src2:"data2"}
  25. 25is this allowed? func(*args, **kwargs)no
  26. 26is this allowed? func(*args, **kwargs, kwargfinal)no
  27. 27how do you unpack a sequence? such as t=(11,12,13,14)use *t , such as in
    func(*t)
  28. 28what does : def print_args(arg1,arg2,*args): print(arg1) print(arg2) print(arg3) t=(11,12,13,14) print_args(*t)11
    12
    (13,14)
  29. 29—

Informações

Descrição
python (beyond basics python flashcards) FlashCards sobre python function characteristics, criado por Andrew Sperazza em 09-01-2017.
Criado por
Andrew Sperazza
Visualizações
10
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?