博客筆記_Python筆記

Hello,週一是一週的開始,要的心境也是好事物的開始,我們每個人都要一直保持開心呦。健康一定是指身體心理都健康,心理健康也是很很很重要的,讓我們一起加油,在追求物質的同時,我們更要把我們的身心調理好。迎接好未來的每一個挑戰,理性做好自我,理性做好自己應該做的事情,縱有天塌下來我們也不要恐懼,因爲比我們壓力大的人有人多很多。天將降大任於斯人也,必先苦其心志、勞其筋骨、餓其體膚。。。。。。

今日PYTHON筆記:

list = [‘a’,’b’,’c’,’d’,’e’]
print list[::-1]

def div1(x,y):
print ‘%s/%s = %s’%(x,y,x/y)

def div2(x,y):
print ‘%s//%s = %s’%(x,y,x//y)
div1(5,2)
div1(5.,2)
div2(5,2)
div2(5.,2.)
def extendList(val,list = []):
list.append(val)
return list
def extendList(val,list=None):
if list is None:
list = []
list.append(val)
return list
list1 = extendList(10)
list2 = extendList(123,[])
list3 = extendList(‘a’)
print list1
print list2
print list3

a = 5
def fn():
global a
a = 4
fn()
print (a)

import os
import sys
import re
import math
import datetime

dic = {‘name’:’zs’,’age’:18}
del dic[‘name’]
print dic
dic2 = {‘name’:’ls’}
dic.update(dic2)
print dic

GIL是python的全局解釋器鎖,同一進程中假如有多個線程運行,一個線程在運行python程序的時候會霸佔python

解釋器(加了一把鎖即GIL),使該進程內的其他線程無法運行,等該線程運行完後其他線程才能運行。如果線程運行過程中遇到耗時操作,則解釋器鎖解開,使其他線程運行。所以在多線程中,線程的運行仍是有先後順序的,並不是同時進行。
多進程中因爲每個進程都能被系統分配資源,相當於每個進程有了一個python解釋器,所以多進程可以實現多個進程的同時運行,缺點是進程系統資源開銷大

list = [11,12,13,12,15,16,13]
a = set(list)
print a
print [x for x in a]

def demo(**args_v):
for k,v in args_v.items():
print k,v
demo(name = ‘b’)

print range(10)

int/bool/str/list/tuple/dict

class Bike:
def init(self,newWheelNum,newColor):
self.wheelNum = newWheelNum
self.color = newColor
def move(self):
print(‘車會跑’)
BM = Bike(2,’green’)
print (‘車的顏色爲:%s’%BM.color)
print (‘車輪子數量爲:%d’%BM.wheelNum)

class A(object):
def init(self):
print (‘這是init方法’,self)
def new(cls):
print (‘這是cls的ID’,id(cls))
print (‘這是new方法’,object.new(cls))
return object.new(cls)
A()
print (‘這是類A的ID’,id(A))

f = open(‘./poem.txt’,’wb’)
try:
f.write(‘hello,world666666’)
except:
pass
finally:
f.close()

list = [1,2,3,4,5]
def fn(x):
return x**2
res = map(fn,list)
print res
res = [i for i in res if i>10]
print res

import random
import numpy as np
result = random.randint(1,2)
res = np.random.randn(5)
ret = random.random()
print (‘正整數’,result)
print (‘5個隨機小數’,res)
print (‘0-1隨機小數’,ret)

import re
str = ‘

中國

res = re.findall(r’
(.*?)
‘,str)
print (res)

a = 3
assert(a>1)
print(‘斷言成功,程序繼續向下執行’)
b = 4
assert(b>7)
print(‘斷言失敗,程序報錯’)

select distinct name from student

ls pwd cd touch rm mkdir tree cp mv cat more grep echo
ls pwd cd touch rm mkdir tree cp mv cat more grep echo

python2和python3區別?列舉5個

1、Python3 使用 print 必須要以小括號包裹打印內容,比如 print(‘hi’)

Python2 既可以使用帶小括號的方式,也可以使用一個空格來分隔打印內容,比如 print ‘hi’

2、python2 range(1,10)返回列表,python3中返回迭代器,節約內存

3、python2中使用ascii編碼,python中使用utf-8編碼

4、python2中unicode表示字符串序列,str表示字節序列

  python3中str表示字符串序列,byte表示字節序列

5、python2中爲正常顯示中文,引入coding聲明,python3中不需要

6、python2中是raw_input()函數,python3中是input()函數

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章