欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

python

Python之as关键字的三种用法 有大用 有大大用

前言

    as关键字,常用的3种方式,建议掌握


普通分类: 

Python 中 pass 语句的作用是什么? 有大用 有大大用

在Python中,pass语句是一个空语句,它的作用是占位符,用于在代码中占据一个位置,以便以后填充。它通常用于在代码中临时占用一个位置,以便以后填充代码,或者在开发过程中留下一些未完成的代码块。

普通分类: 

Python类的继承(非常详细) 有大用

继承是面向对象程序设计的重要概念之一。

普通分类: 

python python3 的print()函数的用法图文讲解 有大用 有大大用

Python 3 print 函数 基础代码

1、print语法格式

普通分类: 

【sock_stream和sock_dgram】、 【AF_INET和AF_UNIX】 区别 有大用 有大大用

【sock_stream和sock_

普通分类: 

python id()函数是什么 有大用

我们每一个人都有身份证来证明自己的身份。网络地址也有,那就是id。网络id可以用来表示计算机属于哪个网络。Python中也有id函数,而Python中每个对象拥有唯一的内存id,所以id函数它主要用于获取指定对象的内存id值,是Python中必不可少的内置函数。本文主要介绍id函数和它的具体使用示例。

普通分类: 

python中main.py是什么意思_关于python:什么是__main__.py? 有大用

普通分类: 

‘pip’ 不是内部或外部命令,也不是可运行的程序或批处理文件解决方案。有大用

普通分类: 

Python安装路径在哪里? 有大用 有大大用

Python是一种流行的编程语言,许多开发者在他们的计算机上安装了Python以便于编写代码。但是,有些人可能会困惑Python被安装在哪个路径?这篇文章将会告诉您。

普通分类: 

python 教程 有大用 有大大用

6种打包Python代码的方法,让你的程序变成exe应用! 有大用

Python是一种高级编程语言,它具有易学易用、跨平台等优点,因此在开发中得到了广泛的应用。

普通分类: 

developer-tools 1.0.7 开发者工具 安装 有大用 有大大用

普通分类: 

vscode vscode在开发python时 Auto Import 失效(代码不自动提示)有大用

首次使用Python开发的时候,发现

普通分类: 

Python try except else(异常处理)用法详解 有大用 有大大用

Python 的异常处理机制可以让程序具有极好的容错性,让程序更加健壮。

普通分类: 

python随机数(random) 有大用

需要导入的库:

import random
import string
  • 1

  • 2

普通分类: 

pip命令使用详解 有大用

pip很像CentOS系统中的yum命令,用于安装及维护Python包。

普通分类: 

async/await 廖雪峰

async/await

阅读: 6846267

普通分类: 

python中items =[[x, y]for (y, x) in pairs]是什么意思

    普通分类: 

    马哥 今日小技巧 关键代码可以依赖于扩展包 有大用

    普通分类: 

    马哥 今日小技巧 【Python小技巧】如何将一串大写字符转化成小写? 有大用

    普通分类: 

    马哥 今日小技巧 优化循环 有大用

    普通分类: 

    马哥 今日小技巧 python 使用新版本 有大用

    任何一个在线上搜索Python资料的人都会发现无数关于Python版本迁移的信息。通常,Python每一个版本都针对之前的一个版本做了优化和改进,以让Python运行的更快。限制因素是你喜欢的函数库是否也针对Python的新版本做了改进。

    普通分类: 

    马哥 今日小技巧 itertools生成排列 有大用



    # itertools生成排列


    # itertools.permutations() generates permutations 


    # for an iterable. Time to brute-force those passwords ;-)


    >>> import itertools


    >>> for p in itertools.permutations('ABCD'):


    ...     print(p)


    ('A', 'B', 'C', 'D')


    ('A', 'B', 'D', 'C')


    ('A', 'C', 'B', 'D')


    ('A', 'C', 'D', 'B')


    ('A', 'D', 'B', 'C')


    ('A', 'D', 'C', 'B')

    普通分类: 

    马哥 今日小技巧 使用dis查看python虚拟机中字节码 有大用

    # You can use Python's built-in "dis"

    # module to disassemble functions and

    # inspect their CPython VM bytecode:


    >>> def greet(name):

    ...     return 'Hello, ' + name + '!'


    >>> greet('Dan')

    'Hello, Dan!'


    >>> import dis

    >>> dis.dis(greet)

    2   0 LOAD_CONST     1 ('Hello, ')

        2 LOAD_FAST      0 (name)

        4 BINARY_ADD

        6 LOAD_CONST     2 ('!')

        8 BINARY_ADD

       10 RETURN_VALUE


    普通分类: 

    马哥 今日小技巧 字典中get方法设置默认值 有大用

     字典中get方法设置默认值



    # The get() method on dicts

    # and its "default" argument


    name_for_userid = {

        382: "Alice",

        590: "Bob",

        951: "Dilbert",

    }


    def greeting(userid):

        return "Hi %s!" % name_for_userid.get(userid, "there")


    >>> greeting(382)

    "Hi Alice!"


    >>> greeting(333333)

    "Hi there!"


    普通分类: 

    马哥 今日小技巧 类方法和静态方法 实例方法差异 有大用

    # @classmethod vs @staticmethod vs "plain" methods

    # What's the difference?


    class MyClass:

        def method(self):

            """

            Instance methods need a class instance and

            can access the instance through `self`.

            """

            return 'instance method called', self


        @classmethod

        def classmethod(cls):

            """

            Class methods don't need a class instance.

            They can't access the instance (self) but

    普通分类: 

    马哥 今日小技巧 s = "ajldjlajfdljfddd",去重并从小到大排序输出"adfjl" 有大用

    s = "ajldjlajfdljfddd",去重并从小到大排序输出"adfjl"

    先使用set去重特性,然后排序,再通过join方法连接成字符串,代码如下


    s = "ajldjlajfdljfddd"

    s = set(s)

    s = sorted(s)

    print(‘’.join(s))



    来自  http://ke.magedu.com/article/112

    普通分类: 

    马哥 今日小技巧 按键值升序排序 通过sorted结合key参数排序 有大用

    dic={"name":"zs","age":18,"city":"深圳","tel":"1362626627"},按键值升序排序


    通过sorted结合key参数排序,再重新组成字典


    dic = {"name":"zs","age":18,"city":"深圳","tel":"1362626627"}


    tmp = sorted(dic.items(), key=lambda x: x[0])


    print(dict(tmp))


    来自  http://ke.magedu.com/article/113

    普通分类: 

    马哥 今日小技巧 Python的try语句中except、else和finally的区别 有大用

    except 为try语句块内发生异常时执行


    else 为try语句块内未发生异常时执行


    finally 不管是否有异常发生都会执行


    来自  http://ke.magedu.com/article/115?tdsourcetag=s_pctim_aiomsg

    普通分类: 

    马哥 今日小技巧 运用python切片技巧 有大用

    # You can clear all elements from a list:

    >>> lst = [1, 2, 3, 4, 5]

    >>> del lst[:]

    >>> lst

    []


    # You can replace all elements of a list

    # without creating a new list object:

    >>> a = lst

    >>> lst[:] = [7, 8, 9]

    >>> lst

    [7, 8, 9]

    >>> a

    [7, 8, 9]

    >>> a is lst

    True


    # You can also create a (shallow) copy of a list:

    >>> b = lst[:]

    >>> b

    [7, 8, 9]

    >>> b is lst

    普通分类: 

    页面

    Subscribe to RSS - python