Learning python - Phase Summary

1. compiled and interpreted programming language

  Compiled: first code into machine code -> register takes the computer is running: C

      Put code into XXX -> computer looking for a virtual machine to execute code -> machine code is turned into machine code to the computer to run: c, java, c #

  Interpreted: side edge explanation execute: python

2. The relationship between bits and bytes:

  1 byte 8

3.b, B, KB, MB, GB relationship:

  8b=1B、1024B=1KB。。。。

4. How conversion strings and lists:

  String transfer list: '' ([xx ',' ff '] join).'

  String transfer list: list ( 'xxxxx') / split

The inverted write code string implemented as v = 'oldboy'

  . A Fanqie: v [:: - 1]

  b. Place the string into a list using the reverse method, the conversion back to a string

The maximum number of layers 6.python recursion

  Official website: 1000

The difference 7.python2 and python3

  a. & encoded string

    String

      py2: 3 types: unicode v = u'root '(Unicode) essentially stored as Unicode

                str / bytes (as Talia) v = 'root' nature of bytes stored

      py3: 2 types: str v = 'root' with unicode storage (Unicode) nature

               bytes v = b'root 'bytes stored essentially

    coding

      py2: ascii file header can be modified: # - * - encoding: utf-8 - * -

      py3: utf-8 header can be modified: # - * - encoding: gbk - * -

      

  b.py2: Classic / new-style class; find new class inheritance depth-first

     py3: new-style class (inherited object): look for inheritance algorithm using c3

 

  c. range

    py2: range (100): generation number 100, and the display / xrange (100) creates a number with a

    py3: range (100) to create a number with a

  In addition to the division bottom plate d.py2

   py3 decimals

  e. Enter

    py2: v1 = raw_input ( 'Enter:')

    py3: v2 = input ( 'Enter:')

  f.print:

    py2:print 'xx'

    py3:print(123)

8. The value exchange achieved by line of code:

a = 1
b = 2
a,b = 2,1

 

9. Comparison: a = [1,2,3] and b = [(1), (2), (3)] and c = [(1,) (2,) (3,)] distinction

  a == b; c in three tuple

  After writing Ganso must be behind the increase, 

    v = (1,2,3,)

  Django framework static configuration file must be written so tuple

10. The result of evaluating:

= V [ the lambda : X for X in Range (10 )]
 Print (V) # 10 functions
 Print (V [0]) # first function
 Print (V [0] ()) #. 9 (at this time x = 9)

 This question derivation:

. 1 .puthon is a function in scope;
 for I in Range (10 ):
     Pass 
Print (I) # . 9 
given
 DEF FUNC ():
     for I in Range (10 ):
         Pass 
FUNC () 
Print (I) # . 9 
2 .lambda expression 
F1 = the lambda X: X +. 1 
func_list = []
 for I in Range (10 ): 
    func_list.append (F1) 
# I =. 9 
# execute a function: the function code is called internally 
func_list [0] (7)
 3 . Formula listing 
Val = [ the lambda X: X + I for I in Range (10 )] 
RET = Val [2] (. 6 )
 Print (RET)

 

 11.re difference of the match and search

  match is to start from scratch to find

  search in which you can find on it

 12. how "1,2,3" becomes [ '1', '2', '3']

str = '1,2,3'
lst = str.split(',')
print(lst)

 

 13.msg = '123.33.sdhf3424.34fdg323.324' calculation and all the numbers in the string

  The results of this question should be: 123.33 + 323.32 + 3424.34

14. Create a function closure which points need to meet?

  Access function in the inner layer outer function local variables

15. The three characteristics of object-oriented

  Inheritance, encapsulation, polymorphism

16. exemplified for all members of the object and is represented by the code

 

17. A look at the code written results

class StarkConfig(object):
    def __init__(self,num):
        self.num = num
    def run(self):
        self()
    def __call__(self, *args, **kwargs):
        print(self.num)

class RoleConfig(StarkConfig):
    def __call__(self, *args, **kwargs):
        print(345)
    def __getitem__(self, item):
        return self.num[item]
v1 = RoleConfig('alex')
v2 = StarkConfig("wupeiqi")
print(v1[1])
print(v2[2])
 
 
Print (v1 [. 1]) # behind a subject v1 [] __getitem__ automate the method, the output L 
Print (V2 [2]) # V2 behind the subject [] __getitem__ automate the method, the output p
result

 

 

18. A look at the code written results

class UserInfo(object):
    pass
class Department(object):
    pass
class StarkConfig(object):
    def __init__(self,num):
        self.num = num
    def changelist(self,request):
        print(self.num,request)
    def run(self):
        self.changelist(999)
class RoleConfig(StarkConfig):
    def changelist(self,request):
        print(666,self.num)
class AdminSite(object):
    def __init__(self):
        self._registry = {}
    def register(self,k,v):
        self._registry[k] = v(k)
site = AdminSite()
site.register(UserInfo,StarkConfig)
site.register(Department,RoleConfig)
for k,row in site._registry.items():
    row.run()
<class '__main__.UserInfo'> 999
666 <class '__main__.Department'>
result

 

19. A look at the code written results

class F3(object):
    def f1(self):
        ret = super().f1()
        print(ret)
        return 123
class F2(object):
    def f1(self):
        print('123')
class F1(F3,F2):
    pass

obj = F1()
obj.f1()
123
None
result

 

20. How an object programming a iterables

  __Iter__ class write method, and returns an iterator iter ([11,22,33,])

21. The role of the interface constraints derived class must those

22. cs simulation game

  1. characters are divided into two kinds of police and gangsters, defined as two classes

  • All police officers are police role

  · Each police has its own name, life, weapons, sex

  • Each shot can attack the enemy, and the target can not be a police

  · All roles are the culprits of terrorist

  • Each has its own name the culprits, life, weapons, sex

  • Each shot can attack the enemy, and can not be a terrorist target

  2. Examples of a policeman, a gangster, police attack terroir, the culprits DOT

  3. extracting the culprit in Police and class similarities defined as a parent class inheritance reduce code reuse manner

class Base(object):
    def __init__(self,name,gender,life_value,weapon):
        self.name = name
        self.gender = gender
        self.life_value = life_value
        self.weapon = weapon
class Police(Base):

    def introduction(self):
        '''自我介绍'''
        tpl = '我是警察,我叫:%s' %(self.name)
        print(tpl)

    def attack(self,other):
        '''
        Police attack culprits, each attack of his life-0, gangster life value -100 
        : param OTHER: Gangster objects 
        ' '' 
        IF isinstance (OTHER, Police):
             Print ( ' ! Police their own people, do not fight ' )
             return 
        Print ( ' police play culprits% s% s ' % (the self.name, other.name,)) 
        self.life_value - = 0 
        other.life_value - = 100 class Terrorist (Base):
     DEF Introduction (self):
         ' '' self introduction '' ' 
        tpl = ' I was the culprit, I called S% ' %

(self.name)
         Print (tpl) 

    DEF Attack (Self, OTHER):
         '' ' 
        gangsters attacked police, each attack of his life value -10; the police health -100 
        : param OTHER: Police target 
        ' '' 
        IF isinstance ( OTHER, Terrorist):
             Print ( ' ! culprits of us, do not fight ' )
             return 
        self.life_value - = 10 
        other.life_value - 100 = 
P1 = Police ( ' Jay ' , ' M ' , 1000, ' gun ' ) 
P2 = Police ( 'Daniel ', ' M ' , 1000, ' Gun ' ) 
T1 = Terrorist ( ' Jie ' , ' M ' , 1000, ' knife ' ) 
T2 = Terrorist ( ' non-filled and ' , ' M ' , 1000, ' knife ' ) 

p1.attack (P2) 
t1.attack (T2) 
p1.attack (T1)

 

Guess you like

Origin www.cnblogs.com/bilx/p/11430552.html