亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

python進階

廖雪峰 移動開發工程師
難度中級
時長 3小時33分
學習人數
綜合評分9.20
575人評價 查看評價
9.6 內容實用
9.0 簡潔易懂
9.0 邏輯清晰
from functools import reduce
def calc_prod(lst):
def quad():
return reduce(ji,lst)
return quad
def ji(x,y):
return x * y
f = calc_prod([1, 2, 3, 4])
print(f())

哎還是學py3吧
import numpy

def calc_prod(lst):
return numpy.prod(lst)

f = calc_prod([1, 2, 3, 4])
print(f)
def format_name(s):
return s.title()

print map(format_name, ['adam', 'LISA', 'barT'])
@property可以將方法變為屬性。S.score 沒加就是 S.score()
def __cmp__(self, s):
if self.score<s.score:
return 1
if self.score>s.score:
return -1
if self.score==s.score:
if self.name>s.name:
return 1
if self.name<s.name:
return -1

return 0
%d 整數
%f 浮點數
%s 字符串
%x 十六進制整數
使用方法:
tpl = "i am %s" % "alex"
tpl = "i am %s age %d" % ("alex", 18)
tpl = "i am %(name)s age %(age)d" % {"name": "alex", "age": 18}
tpl = "percent %.2f" % 99.97623
tpl = "i am %(pp).2f" % {"pp": 123.425556, }
tpl = "i am %.2f %%" % {"pp": 123.425556, }
占位符%s既可以表示字符串str,還可以表示整數int,浮點數float;

    占位符%d既可以表示整數int,還可以表示浮點數float(去除整數部分)

    占位符%f既可以表示浮點數float,還可以表示整數int(默認保留6位小數)

            注意:若想自主保留n位小數,可將其表示位%.nf
return math.sqrt(x)%1 == 0
import math

def is_sqr(x):
return math.sqrt(x) in range(1,11)

print filter(is_sqr, range(1, 101))
可以用字符串的title方法,就是將首字母大寫,后邊的字母都是小寫
過時的厲害。。
def calc_prod(lst):
def cprod():
x = 1
for n in lst:
x = n * x
return x
return cprod

f = calc_prod([1, 2, 3, 4])
print f()
確實是在3.0版本中不需要加float關鍵字,可以直接p/q
def calc_prod(lst):
def cheng(x,y):
return x*y
def fiterinfo():
return reduce(cheng,lst)
return fiterinfo

f = calc_prod([1, 2, 3, 4])
print f()
def cmp_ignore_case(s1, s2):
if(s1[0].lower()>s2[0].lower()):
return 1
else:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
課程須知
本課程是Python入門的后續課程 1、掌握Python編程的基礎知識 2、掌握Python函數的編寫 3、對面向對象編程有所了解更佳
老師告訴你能學到什么?
1、什么是函數式編程 2、Python的函數式編程特點 3、Python的模塊 4、Python面向對象編程 5、Python強大的定制類

微信掃碼,參與3人拼團

微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

友情提示:

您好,此課程屬于遷移課程,您已購買該課程,無需重復購買,感謝您對慕課網的支持!

本次提問將花費2個積分

你的積分不足,無法發表

為什么扣積分?

本次提問將花費2個積分

繼續發表請點擊 "確定"

為什么扣積分?

舉報

0/150
提交
取消