博客笔记_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()函数

猜你喜欢

转载自blog.csdn.net/qq_25213395/article/details/82352455