性少妇vide0seⅹfree_国产剧情视频在线观看_日日碰夜夜爽_九九这里只有精品视频_性free毛茸茸偷窥videos_国产v亚洲

中培偉業(yè)IT資訊頻道
您現(xiàn)在的位置:首頁 > IT資訊 > 軟件研發(fā) > Python的做事方式是什么?

Python的做事方式是什么?

2020-08-28 17:52:28 | 來源:中培企業(yè)IT培訓網(wǎng)

今天要介紹的是關于使用簡單的方法解決python問題的。作為一名編碼人員,從描述數(shù)據(jù)類型開始學習和解釋語言新概念的方法。那么python中的數(shù)據(jù)類型是什么? 數(shù)據(jù)類型或簡單類型是數(shù)據(jù)的屬性,它告訴解釋器程序員打算如何使用數(shù)據(jù)。眾所周知,python中最常見的數(shù)據(jù)類型是float(浮點數(shù)),int(整數(shù)),str(字符串),bool(布爾值),列表和dict(字典)。但是與C或C ++不同,Python將自動確定將數(shù)據(jù)存儲為哪種數(shù)據(jù)類型。但是您需要了解數(shù)據(jù)類型,才能將數(shù)據(jù)從一種類型轉換為另一種類型(也稱為Typecasting或Type conversion)。讓我們看一個基本數(shù)據(jù)類型(清單)的示例,以整體上理解語言和編程。

## I am simply creating a list and printing out the type of indivisual elements in the list ..

List = [1,2.0,"Hello World",True,[1,2,3,4,5],{'key':'value'}]# I am using for in loop because the size of the list is fixed ..for element in List:

print(type(element))# or you can also use list compreshension

elements = [type(element) for element in List]

print(elements)

  #output //

<CLASS'INT'>

<CLASS'FLOAT'>

<CLASS'STR'>

<CLASS'BOOL'>

< class'list'> <

class'dict'>

[<CLASS'INT'>,,<CLASS'STR'>,<CLASS'BOOL'>,<CLASS'LIST'>,<CLASS'DICT'>]]

記住 —除了python提供的數(shù)據(jù)結構外,我們可以在python中創(chuàng)建自己的數(shù)據(jù)結構。您要做的就是創(chuàng)建一個類,并在該類中定義自己的方法。這 就是創(chuàng)建熊貓數(shù)據(jù)框的方法……但是我有一天會寫它。現(xiàn)在,讓我們堅持一些基本知識!

  基本清單方法

讓我們看一下一些List方法,用于從列表中插入和刪除元素…

1. append:在列表中添加元素。性能:將元素附加到列表末尾的時間復雜度為o(1),而其他任何地方均為o(n)

2. remove:刪除列表中的元素。性能:刪除列表中元素的時間復雜度為o(n)

搜索列表中元素的時間復雜度始終為o(1)

## List Methods ...

# insertion

List.append((1,5.0))

print(List)

# seraching an element in the list which is already in a list ...

list_in_list = List[4][0]

print(list_in_list)

# deletion

List.remove(1)

print(List)

#output //

[1,2.0,'Hello World',True,[1,2,3,4,5],{'key':'value'},(1,5.0)]

1

[2.0,'Hello世界”,真,[1、2、3、4、5],{'鍵':'值'},(1、5.0)]

  操作清單項目

1. lambda函數(shù):它們以1行編寫,用于定義自定義函數(shù);

2. map()方法(在DataScience中也稱為向量方法):使用map函數(shù)將您定義的自定義函數(shù)映射到列表的每個元素。map方法采用2個參數(shù),您要應用的功能b。列出您想要上述功能的應用;

3. enumerate()方法: enumerate()方法將計數(shù)器添加到可迭代對象并返回它。返回的對象是一個枚舉對象。

custom_list = [[1,2,3,4,5],["Cat","Dog","Dog","Tiger","Lion","Goat"]]

# custom function to find square of a number

def square_of_number(x):

return x*x

# using lambda functions to create a new list from exisitng list but with cube of each items in the list..

cube_of_number = lambda x:x*x*x

squares_of_list_items = lambda x:x*x

# using map function to apply a function to all elements of the list

new_list_of_squares = list(map(squares_of_list_items,custom_list[0]))

new_list_of_cubes = list(map(cube_of_number,custom_list[0]))

print(new_list_of_squares)

print(new_list_of_cubes)

# Using Enumerate to find the count of Each animal in custum_list

for i,x in enumerate(custom_list[1]):

print('iterater is :', i ,'and value is ', x)

#output //

[ 1、4、9、16、25

]

[1、8、27、64、125 ] <枚舉對象,位于0x7f0cf44e4b40>

iterater為:0,值為Cat

迭代器:1,值為Dog

迭代器:2并且值是Dog

迭代器是:3和值是Tiger

迭代器是:4并且值是Lion

迭代器是:5并且值是山羊

  發(fā)電機和裝飾器:

1. Python生成器是創(chuàng)建迭代器/可迭代對象的簡單方法。它可以在函數(shù)調用時暫停,也可以在整個程序的生命周期中通過使用next()函數(shù)在任何時間恢復。

2.裝飾器是python中的一流對象。這意味著它們可以在任何函數(shù)中通過引用傳遞。裝飾器只是一個奇特的名稱,也是將函數(shù)作為參數(shù)傳遞給另一個函數(shù)的方式。它們也被稱為可調用對象,它接受一個函數(shù)并返回或改變該函數(shù)的行為。

# Generators :

def generator():

for i in range(5):

yield i

print(generator) # output://

a = generator()

print(next(a)) # output:// 0

print(next(a)) # output:// 1

# Decorators

def function1():

print('this is function 1')

def function2(function_argument):

function_argument()

print('this is function 2')

new_object = function2(function1) # output:// this is function 1 this is function 2

# using it as a decorator function ...

@function2

def function1():

print('this is function 1') # output:// this is function 1 this is function 2

* args和** kwargs

args和** kwargs是最重要的關鍵字,在我的編碼風格和編程實踐中,我個人經(jīng)常使用它們。好吧,想象一下!您正在創(chuàng)建函數(shù),卻不知道預期的參數(shù)數(shù)量。在這種情況下,我們使用* args,如果它是字典,則使用** kwargs。

def arr(*args):

for i in args:

print(i)

arr(1,2,3,4) # output: // 1 2 3 4

arr(1,2) # output:// 1 2

Python是一種很棒的編程語言。它易于學習且易于實施。它支持許多程序包,因此許多黑客,數(shù)據(jù)科學家和后端開發(fā)人員都使用它來執(zhí)行日常任務。想了解更多關于Python的信息,請繼續(xù)關注中培偉業(yè)。

主站蜘蛛池模板: 亚洲欧美日韩v在线观看不卡 | 国产a久久久 | 丰满的邻居k8经典 | 国产三级精品三级在线观看国产 | 亚洲综合av色婷婷 | 草草影视CCYY国产日本 | 三级电影在线播放 | 奇米四色777久久爱 国产对白在线播放 | 日本爽快片18禁免费看 | eeuss鲁丝片一区二区三区 | 中国久久久久 | 亚洲欧美日韩精品久久久 | 久久九九有精品国产23 | 俄罗斯毛片基地 | 久草免费福利视频 | 7777久久亚洲中文字幕 | 特大巨人黑人AAA片BBC | 日本爽快片100色毛片 | 日韩一欧美内射在线观看 | 欧美伊人精品成人久久综合97 | 肉大捧一进一出免费网址 | 嫩草影院ncyy入口 | 亚洲第一在线视频 | 亚洲 欧美 日本精品 | 国产精口品美女乱子伦高潮 | 日韩天堂在线观看 | 日本免费一二三区 | 狠狠干导航 | 国产自产一区二区 | 在线观看一级 | 漂亮的保姆免费观看 | 亚洲欧美日本视频在线观看 | 国产资源免费观看 | 一道本啪啪 | 免费观看很黄很色裸乳视频网站 | 国语片激情放荡的少妇在线播放 | 日本少妇XXXX做受 | 国产熟妇视频在线观看 | 污视频网站免费观看 | 太平公主作爱a级毛片 | h小视频在线观看 |