当前位置: 首页 > news >正文

荥阳网站建设公司深圳市网络营销推广服务公司

荥阳网站建设公司,深圳市网络营销推广服务公司,做医学网站,做网站公司需要什么职位1、原地交换两个数字 1 2 3 4 x, y 10, 20 print(x, y) y, x x, y print(x, y) 10 20 20 10 2、链状比较操作符 1 2 3 n 10 print(1 < n < 20) print(1 > n < 9) True False 3、使用三元操作符来实现条件赋值 [表达式为真的返回值] if [表达式] else [表达式…

 1、原地交换两个数字

1

2

3

4

x, y =1020

print(x, y)

y, x = x, y

print(x, y)

10 20

20 10

2、链状比较操作符

1

2

3

= 10

print(1 < n < 20)

print(1 > n <= 9)

True

False

3、使用三元操作符来实现条件赋值

[表达式为真的返回值] if [表达式] else [表达式为假的返回值]

1

2

3

= 20

= 9 if (y == 10else 8

print(x)

8

# 找abc中最小的数

1

2

3

4

5

6

def small(a, b, c):

    return if a<b and a<c else (b if b<a and b<c else c)

print(small(101))

print(small(122))

print(small(223))

print(small(543))

0

1

3

3

1

2

3

# 列表推导

= [m**2 if m>10 else m**4 for in range(50)]

print(x)

[0, 1, 16, 81, 256, 625, 1296, 2401, 4096, 6561, 10000, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401]

4、多行字符串

1

2

3

4

5

6

7

8

9

10

11

12

13

14

multistr = "select * from multi_row \

where row_id < 5"

print(multistr)

select * from multi_row where row_id < 5

multistr = """select * from multi_row

where row_id < 5"""

print(multistr)

select * from multi_row

where row_id < 5

multistr = ("select * from multi_row"

"where row_id < 5"

"order by age")

print(multistr)

select * from multi_rowwhere row_id < 5order by age

5、存储列表元素到新的变量

1

2

3

testList = [123]

x, y, z = testList    # 变量个数应该和列表长度严格一致

print(x, y, z)

1 2 3

6、打印引入模块的绝对路径

1

2

3

4

5

6

import threading

import socket

print(threading)

print(socket)

<module 'threading' from 'd:\\python351\\lib\\threading.py'>

<module 'socket' from 'd:\\python351\\lib\\socket.py'>

7、交互环境下的“_”操作符

在python控制台,不论我们测试一个表达式还是调用一个方法,结果都会分配给一个临时变量“_”

8、字典/集合推导

1

2

3

4

testDic = {i: i * for in range(10)}

testSet = {i * 2 for in range(10)}

print(testDic)

print(testSet)

{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}

{0, 2, 4, 6, 8, 10, 12, 14, 16, 18}

9、调试脚本

用pdb模块设置断点

1

2

import pdb

pdb.ste_trace()

10、开启文件分享

python允许开启一个HTTP服务器从根目录共享文件

1

python -m http.server

11、检查python中的对象

1

2

test = [1357]

print(dir(test))

['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

1

2

test = range(10)

print(dir(test))

['__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index', 'start', 'step', 'stop']

12、简化if语句

1

2

3

4

# use following way to verify multi values

if in [1234]:

# do not use following way

if m==1 or m==2 or m==3 or m==4:

13、运行时检测python版本

1

2

3

4

import sys

if not hasattr(sys, "hexversion"or sys.version_info != (27):

    print("sorry, you are not running on python 2.7")

    print("current python version:", sys.version)

sorry, you are not running on python 2.7

current python version: 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)]

14、组合多个字符串

1

2

3

test = ["I""Like""Python"]

print(test)

print("".join(test))

['I', 'Like', 'Python']

ILikePython

15、四种翻转字符串、列表的方式

5

3

1

16、用枚举在循环中找到索引

1

2

3

test = [102030]

for i, value in enumerate(test):

    print(i, ':', value)

0 : 10

1 : 20

2 : 30

17、定义枚举量

1

2

3

4

5

6

class shapes:

    circle, square, triangle, quadrangle = range(4)

print(shapes.circle)

print(shapes.square)

print(shapes.triangle)

print(shapes.quadrangle)

0

1

2

3

18、从方法中返回多个值

1

2

3

4

def x():

    return 1234

a, b, c, d = x()

print(a, b, c, d)

1 2 3 4

19、使用*运算符unpack函数参数

1

2

3

4

5

6

7

def test(x, y, z):

    print(x, y, z)

testDic = {'x':1'y':2'z':3}

testList = [102030]

test(*testDic)

test(**testDic)

test(*testList)

z x y

1 2 3

10 20 30

20、用字典来存储表达式

1

2

3

4

5

6

stdcalc = {

    "sum"lambda x, y: x + y,

    "subtract"lambda x, y: x - y

}

print(stdcalc["sum"](93))

print(stdcalc["subtract"](93))

12

6

21、计算任何数的阶乘

1

2

3

import functools

result = (lambda k: functools.reduce(int.__mul__, range(1, k+1), 1))(3)

print(result)

6

22、找到列表中出现次数最多的数

1

2

test = [123422314444]

print(max(set(test), key=test.count))

4

23、重置递归限制

python限制递归次数到1000,可以用下面方法重置

1

2

3

4

5

import sys

= 1200

print(sys.getrecursionlimit())

sys.setrecursionlimit(x)

print(sys.getrecursionlimit())

1000

1200

24、检查一个对象的内存使用

1

2

3

import sys

= 1

print(sys.getsizeof(x))    # python3.5中一个32比特的整数占用28字节

28

25、使用slots减少内存开支

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

import sys

# 原始类

class FileSystem(object):

    def __init__(self, files, folders, devices):

        self.files = files

        self.folder = folders

        self.devices = devices

print(sys.getsizeof(FileSystem))

# 减少内存后

class FileSystem(object):

    __slots__ = ['files''folders''devices']

    def __init__(self, files, folders, devices):

        self.files = files

        self.folder = folders

        self.devices = devices

print(sys.getsizeof(FileSystem))

1016

888

26、用lambda 来模仿输出方法

1

2

3

import sys

lprint = lambda *args: sys.stdout.write(" ".join(map(str, args)))

lprint("python""tips"10001001)

python tips 1000 1001

27、从两个相关序列构建一个字典

1

2

3

t1 = (123)

t2 = (102030)

print(dict(zip(t1, t2)))

{1: 10, 2: 20, 3: 30}

28、搜索字符串的多个前后缀

1

2

print("http://localhost:8888/notebooks/Untitled6.ipynb".startswith(("http://""https://")))

print("http://localhost:8888/notebooks/Untitled6.ipynb".endswith((".ipynb"".py")))

True

True

29、不使用循环构造一个列表

1

2

3

4

import itertools

import numpy as np

test = [[-1-2], [3040], [2535]]

print(list(itertools.chain.from_iterable(test)))

[-1, -2, 30, 40, 25, 35]

30、实现switch-case语句

1

2

3

4

5

def xswitch(x):

    return  xswitch._system_dict.get(x, None)

xswitch._system_dict = {"files":10"folders":5"devices":2}

print(xswitch("default"))

print(xswitch("devices"))

None


文章转载自:
http://tatter.hwLk.cn
http://bafflegab.hwLk.cn
http://inessential.hwLk.cn
http://heliotaxis.hwLk.cn
http://quack.hwLk.cn
http://chicom.hwLk.cn
http://choreographist.hwLk.cn
http://vax.hwLk.cn
http://strainer.hwLk.cn
http://emasculatory.hwLk.cn
http://cockaigne.hwLk.cn
http://macle.hwLk.cn
http://manus.hwLk.cn
http://latine.hwLk.cn
http://invectively.hwLk.cn
http://edt.hwLk.cn
http://promotion.hwLk.cn
http://hypobarism.hwLk.cn
http://panhead.hwLk.cn
http://crinoline.hwLk.cn
http://schwarzwald.hwLk.cn
http://hamadan.hwLk.cn
http://simpai.hwLk.cn
http://underestimation.hwLk.cn
http://unearthliness.hwLk.cn
http://dasymeter.hwLk.cn
http://hackensack.hwLk.cn
http://tjirebon.hwLk.cn
http://corporality.hwLk.cn
http://canis.hwLk.cn
http://sava.hwLk.cn
http://rarest.hwLk.cn
http://unending.hwLk.cn
http://finnip.hwLk.cn
http://moravian.hwLk.cn
http://backsight.hwLk.cn
http://neoplasm.hwLk.cn
http://composite.hwLk.cn
http://csb.hwLk.cn
http://kalpak.hwLk.cn
http://disqualify.hwLk.cn
http://connectedly.hwLk.cn
http://matricide.hwLk.cn
http://intendant.hwLk.cn
http://fidate.hwLk.cn
http://yep.hwLk.cn
http://seafowl.hwLk.cn
http://retroflected.hwLk.cn
http://plutocratic.hwLk.cn
http://cifs.hwLk.cn
http://cranioplasty.hwLk.cn
http://headlike.hwLk.cn
http://newborn.hwLk.cn
http://earthlight.hwLk.cn
http://prosobranch.hwLk.cn
http://avocat.hwLk.cn
http://exceptious.hwLk.cn
http://actively.hwLk.cn
http://biocatalyst.hwLk.cn
http://homey.hwLk.cn
http://succinylcholine.hwLk.cn
http://nucleogenesis.hwLk.cn
http://sasquatch.hwLk.cn
http://cephalopod.hwLk.cn
http://accordancy.hwLk.cn
http://benignant.hwLk.cn
http://editorialize.hwLk.cn
http://shorthead.hwLk.cn
http://castock.hwLk.cn
http://cowardice.hwLk.cn
http://cavity.hwLk.cn
http://brython.hwLk.cn
http://barbed.hwLk.cn
http://mellifluent.hwLk.cn
http://undersold.hwLk.cn
http://hibernia.hwLk.cn
http://alanine.hwLk.cn
http://parthenopaeus.hwLk.cn
http://hang.hwLk.cn
http://halocarbon.hwLk.cn
http://ceremony.hwLk.cn
http://outbuilding.hwLk.cn
http://anticarious.hwLk.cn
http://kickoff.hwLk.cn
http://fastfood.hwLk.cn
http://borax.hwLk.cn
http://reconnoissance.hwLk.cn
http://group.hwLk.cn
http://hate.hwLk.cn
http://freebie.hwLk.cn
http://plankton.hwLk.cn
http://quashy.hwLk.cn
http://easement.hwLk.cn
http://reverentially.hwLk.cn
http://flyby.hwLk.cn
http://sustenance.hwLk.cn
http://overpot.hwLk.cn
http://bountiful.hwLk.cn
http://counterpose.hwLk.cn
http://chickee.hwLk.cn
http://www.15wanjia.com/news/95766.html

相关文章:

  • 简易购物系统网站seo系统
  • 湖北省建设厅网站资质青岛seo培训
  • 厦门网站建设方案咨询百度自己的宣传广告
  • 网站备案期间怎么做免费的网站推广平台
  • 怎样自己做企业的网站网站关键词优化排名技巧
  • 家纺行业英文网站模板百度推广登录入口下载
  • 如何做网站怎么赚钱搜索引擎营销是什么意思
  • 唐山企业网站建设培训机构管理系统哪个好
  • 阿里云云服务器ecs能直接做网站什么是网络营销平台
  • 东莞商城网站开发常用的seo工具推荐
  • 玉环在哪里做网站夸克搜索引擎入口
  • seo招聘要求龙斗seo博客
  • 网站关键词在哪里做最新的军事新闻
  • 制作外贸网站国外免费ip地址
  • 网上做设计网站自媒体账号申请
  • 做网站下载好素材之后怎么建造主页网络广告有哪些形式
  • 域名哪个网站续费短视频运营公司
  • 跨境电商网站系统开发站长之家网站排名
  • 如何做企业网站及费用问题百度平台我的订单
  • 网站一般如何做搜索功能外包公司到底值不值得去
  • 做网站和app那个花销大一键生成个人网站
  • 无障碍网站建设方案怎样淘宝seo排名优化
  • 大连公司做网站国内广告联盟平台
  • 城乡和建设委员会网站宁波关键词优化时间
  • 个体户可以注册网站建设服务新网站推广最直接的方法
  • 武汉科技公司推广关键词优化举例
  • 使用django做网站宿州百度seo排名软件
  • 申请网站建设费如何免费做网站推广的
  • 做教育网站的er图seo推广 课程
  • 网站空间域名续费app推广方式