2019.8.14 learning content and notes

summary

Recursive function

num = 0
count = 0
while count < 101:
    print(count) # 0--100循环
    num += count
    count += 1
print(num) # 0--100求和

Recursion: progressive; return

count = 0
def f1():
    global count # 修改成全局的count,让下面的count都是全局的count
    count += 1
    print(count) 
    f1()
f1()

Core recursive: progressive when able to reach a result, more and more small scale of the problem (do not have to really reach); set a condition that allows the end of the last function call;

:( recursive recursive code is more of a thinking used to solve some kind of problem)

count = 0                                       
def f1():                                       
    global count # 将局部里面的count修改成全局的count       
    if count > 100:                             
        return                                  
    count += 1                                  
    print(count)                                
    f1()                                        
f1()                                            
s = '{[]}'                           
def isvalid(s: str) ->bool:          
    print(s)                         
    s = ''                           
    if not s:                        
        return True                  
    if s.find('[]') != -1 or s.find('
        if '{}' in s:                
            s = s.replace('{}','')   
        if '[]'in s:                 
            s = s.replace('[]','')   
        if '()'in s:                 
            s = s.replace('()','')   
        if s == '':                  
            return True              
        res = isvalid(s)             
        print(res)                   
        if not res:                  
            return False             
    else:                            
        return True                  
res = isvalid(s)                     
print(res)                           
# 求年龄                            
 # 16/18/20/22/24/26,求第五人的年龄     
                                 
def func(x):                     
    age = 16                     
    age = age + 2*x              
    return age                   
res = func(5)                    
print(res)                       
# 内置方法                          
# abs(绝对值)                      
#print(abs(-10))  # 10          
                                
# bin (二进制)                     
#print(bin(97)) # 0b1100001 :011
                                
# hex (十六进制)                    
#print(hex(97)) # 0x61          
                                
# oct (八进制)                     
# print(oct(97)) # 0o141     

# def func():                              
#     pass                                 
# print('callable(func):',callable(func)) #
#print('callable(1,]):',callable([1,])) # F
                                           
# chr() 返回ascll码对应字符                       
# print(chr(97)) #a                        
                                           
# ord() chr()参考ASCII码表将数字转成对应字符;ord()将字符转换成
#vprint(ord('a'))                          
                                           
# enumerate  将元素按索引位置排列出来                  
# for ind, value in enumerate([1,2,3]):    
#     print(ind,value)   # 0 1             
#                        # 1 2             
#                        # 2 3             
                                           
# eval() 把字符串翻译成数据类型                       
#print("eval('1+1'):", eval('1+1'))# eval('
                                           
# exec()  执行,相当于print,在python2中使用          
# exec('print("12345")')  #12345           
                                           
# 只要记住一个enumerate                          

Process-oriented programming

Split: process-oriented programming

According to the process (assembly line thinking) code Code

A bunch of variables / parameters - "a function (Process a) -" function bis (Process b) - "Result

A process output must be input to the next process

Process-oriented programming advantages: clear thinking

Disadvantages:

  1. A process is finished, the next process is finished
  2. Not separate between function and function
  3. Indeed affect the whole body

Guess you like

Origin www.cnblogs.com/chmily/p/11360118.html