1. Gets the number of elements in the list, the method used to append elements to the end of the list is (), respectively ()
Count, append
2, Judge Dict there is a key to use the method is ()
Inch
3, L = range (100), take first to third element with (), take the second-to-last element (), take the next 10 elements ()
L[:3]L[-2]L[-10:]
4. Copy L to L1 () Note: Non-reference delivery
L1 = L.copy ()
5, D = {' A ': 1, ' B ': 2, ' C ': 3} Please print out Key,value
For k,v in D.items (): print (K,V)
6. How to determine if a variable is a string
Isinstance (A,STR)
7. What is the difference between list and tuple?
8. What is the difference between xrange and range?
9. How do you change to [' 1 ', ' 2 ', ' 3 ']? [' 1 ', ' 2 ', ' 3 '] how to become [the]
S1 = "S2" = List (S1.split (', ')) S3 = List (map (INT,S2))
10. Please answer the following questions?
def add_end (l= []): l.append (' End ') return Lprint (Add_end ()) # Output what? Print (Add_end ()) # Call output again what? Why?
["End"] ["End", "end" function default parameters are allocated memory space at compile time.) Parameters that are not given are used by default parameters and are the same object for the same memory address.
11, [36,5,12,9,21] how to sort?
A = [36,5,12,9,21]a.sort ()
12. Please answer the following questions:
def func (A,b,c=0,*args,**kwargs): What is the role of Pass*args,**kwargs?
You can use *args and **kwargs to pass variable parameters when the parameters of the function are not deterministic. *args stores variable positional parameters, it receives any number of parameters and passes them as tuples to the function. **kwargs stores variable keyword parameters, allowing you to pass any number of keyword arguments as a dictionary to a function using a parameter name that is not defined beforehand. Note the order of the parameters of the function: args must precede kwargs, and calling function pass parameters must also follow this order
13, is and = = The difference is?
Objects in Python contain three elements: ID, type, value where the ID is used to uniquely identify an object, type identifies the object, and value is the values of the object is to determine whether a object is a B object, is determined by the ID = = Determines whether the value of the A object is equal to the value of the B object, as determined by value.
14. How to generate [1,4,9,16,25,36,49,64,81,100]? Try to implement it in one line
[X*x for X in range (1,11)]
15. What is the generator? What's the effect? Please write out a generator
A = (I for I in range (11))
16, Map (str,[1,2,3,4,5,6,7,8,9]) output what?
# generated is the Map object print (list (map (str, [1, 2, 3, 4, 5, 6, 7, 8, 9])) # [' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ']
17, please write the implementation of log (the main function is to print the name of the letter)
@logdef now (): print (' 2013-12-25 ') now () # output: # Call Now () # 2013-12-25
Import functoolsdef Log (func): @functools. Wraps (func) def inner (): print (' call ' + func.__name__ + ' () ') func () return inner
Python----Face Question (iv)