美文网首页
2020-02-15python学习

2020-02-15python学习

作者: 锅炉工的自我修养 | 来源:发表于2020-02-15 23:17 被阅读0次

linux 安装git

grep -i "error:" /var/log/messages | less

python

工作常用别人的代码
设计好 API

def print_if_true(thing,check):
    '''
    Print the first argument if the second argument is true.
    The operation is:
        1. check whther the second argument is true
        2. If it is, print the first argument.
    '''
    if check:
        print(thing)

# use help to get the docstring of a function
help(print_if_true)
print(print_if_true.__doc__) # call the help documentation
?print_if_true # docstring 
---
# This will print a heart shape on the screen
#def print_heat(*args):
a='zhangyanjie'
def print_heat(in_str):
    print('\n'.join([''.join([(in_str
                            [(x-y)%7]
                             if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<0
                             else' ')
                             for x in range(-30,30)])
                    for y in range(15,-15,-1)]))
# This will print a multiplication table
print('\n'.join([''.join(['%s*%s=%-2s' % (y,x,x*y) for y in range(1,x+1)]) for x in range(1,10)]))
---
# default parameters
def print_all_args(req1,option='hello',*args,**kwargs):
    print('required arg1:',req1)
    print('required opt:',option)    
    print('required args:',args)
    print('required kwargs:',kwargs)
# The *args will give you all function parameters as tuple:

# The **kwargs will give you all keyword arguments except for those corrsponding to a formal parameter as a dictionary

---
# 把函数作为变量
def answer1():
    print("I enjoy programing with Python")
    
def answer2():
    print("I'm a sucker for Python")
    
# A Function that takes another function as argument
def run_something(func):
    func() # callback functions

run_something(answer1)
run_something(answer2)




相关文章

  • 2020-02-15python学习

    linux 安装git grep -i "error:" /var/log/messages | less pyt...

  • 学习学习学习

    第三天了,连续三天,早上睁眼开始,看视频,做课件,连续作业,直到晚上十二点才睡觉。吃饭不规律,想起来就吃,感觉不饿...

  • 学习学习学习

    23岁的我,才真正明白,什么是学习,什么是努力,努力和不努力真的不同,就好比同样是一篇稿子,我用一周背下来,有的人...

  • 学习学习学习!

    妈妈总是让我学习,我只能用装当办法。 方法一: 方法二: 方法三: 方法四: ...

  • 学习学习学习

    001.今天看财富自由之路看了第二遍,而且看了一半,算是完成任务很开心。中间有想放弃的念头,坚持看完。眼睛痛,一直...

  • 学习学习学习

    马自达为什么坚持高压缩比自吸

  • 学习!学习!学习!

    学习的痛苦是暂时的 没有学到的痛苦是永恒的 因为学习而特别充实的一天 很踏实 ~~~~ 2015.11.28.阴天...

  • 学习!学习!学习!

    无数次想要去逃离,可这封闭的世界根本出不去。你没有什么可以抛弃、只能咬着牙带着面具微笑的活下去。 没有那个人、他也...

  • 学习学习学习!

    昨天和今天两个上午,都在学习新媒体运营,学习的过程中心里只有一个想法:这也太套路,太功利了吧。可真应了那句话...

  • 学习,学习,学习!

    近期学习重点有两个方面,一方面是把上一个阶段定下任务的几本书读完,并在读的过程中有输出和转化,让阅读和学习真正能有...

网友评论

      本文标题:2020-02-15python学习

      本文链接:https://www.haomeiwen.com/subject/ckoefhtx.html