精华内容
下载资源
问答
  • Python3备忘录.zip

    2020-04-05 15:57:51
    英文版Python3备忘录PDF…
  • Python Django备忘录

    万次阅读 2021-05-19 21:28:36
    Python Django备忘录 前提——基于django2.2.6: pip install django==2.2.6 1、创建django项目 django-admin startproject yourproject 2、创建app python manage.py startapp youapp 3、初始化数据库 python ...

    Python Django备忘录

    前提——基于django2.2.6:

    pip install django==2.2.6
    

    1、创建django项目

    django-admin startproject yourproject
    

    2、创建app

    python manage.py startapp youapp
    

    3、初始化数据库

    python manage.py makemigrations
    python manage.py migrate
    

    4、静态文件路径指定settings.py

    'DIRS': [os.path.join(BASE_DIR,'templates')]
    

    5、多app路由分发
    app.urls.py

    path('tosearch/', views.tosearch,name='tosearch')
    

    project.urls.py

    path('admin/', admin.site.urls),
    path('skynet/',include((skynet_urls,'skynet'),namespace='skynet'))
    

    templates.index.html

    <a href="{% url 'skynet:tosearch' %}">查询</a>
    
    展开全文
  • 流利的Python备忘录 我阅读流利的Python的备忘录
  • python 桌面备忘录The printable version of this cheat sheet 该备忘单的可打印版本 It’s common when first learning Python for Data Science to have trouble remembering all the syntax that you need. ...

    python 桌面备忘录

    The printable version of this cheat sheet

    该备忘单的可打印版本

    It’s common when first learning Python for Data Science to have trouble remembering all the syntax that you need. While at Dataquest we advocate getting used to consulting the Python documentation, sometimes it’s nice to have a handy reference, so we’ve put together this cheat sheet to help you out!

    第一次学习Python for Data Science时,通常很难记住您需要的所有语法。 Dataquest时,我们提倡习惯于查阅Python文档 ,有时可以得到一些方便的参考,这很高兴,因此我们整理了这份备忘单,可以为您提供帮助!

    If you’re interested in learning Python, we have a free Python Programming: Beginner course which can start you on your data science journey.

    如果您对学习Python感兴趣,我们有一个免费的Python编程:入门课程,可以帮助您开始数据科学之旅。

    –>

    –>

    关键基础知识,打印和获得帮助 (Key Basics, Printing and Getting Help)

    x = 3x = 3 3 to the variable 3赋给变量xx
    print(x)print(x) xx的值
    type(x)type(x) Return the type of the variable x (in this case, int for integer) 返回变量x的类型(在这种情况下, intint
    help(x)help(x) str data typestr数据类型的文档
    help(print)help(print) print() functionprint()函数的文档

    读取文件 (Reading Files)

    f = open("my_file.txt", "r")
    file_as_string = f.read()
    f = open("my_file.txt", "r")
    file_as_string = f.read()
    
    my_file.txt and assign its contents to my_file.txt并将其内容分配给singsing
    my_dataset.csv and assign its data to the list of lists my_dataset.csv并将其数据分配给列表csv_as_listcsv_as_list的列表

    弦乐 (Strings)

    s = "hello"s = "hello" "hello" to the variable "hello"分配给变量ss
    s = """She said,
    "there's a good idea."
    """
    s = """She said,
    "there's a good idea."
    """
    
    s. Also used to create strings that contain boths 。 也用于创建同时包含" and "' characters.'字符的字符串。
    len(s)len(s) ss的字符数
    s.startswith("hel")s.startswith("hel") s starts with the substring s是否以子字符串"hel""hel"开头
    s.endswith("lo")s.endswith("lo") s ends with the substring s是否以子字符串"lo""lo"结尾
    "{} plus {} is {}".format(3,1,4)"{} plus {} is {}".format(3,1,4) 3, 31, and 1 ,和4 inserted4插入
    s.replace("e","z")s.replace("e","z") s with all occurances of s返回一个新字符串,所有出现的"e" replaced with "e"替换为"z""z"
    s.strip()s.strip() s with any whitespace at the start and end of the string removeds的新字符串,并在字符串的开头和结尾删除了空格
    s.split(" ")s.split(" ") s into a list of strings, separating on the character s拆分为字符串列表,以字符" " and return that list" "分隔并返回该列表

    数值类型和数学运算 (Numeric Types and Mathematical Operations)

    i = int("5")i = int("5") "5" to the integer "5"转换为整数5 and assign the result to 5并将结果分配给ii
    f = float("2.5")f = float("2.5") "2.5" to the float value "2.5"转换为浮点值2.5 and assign the result to 2.5 ,并将结果分配给ff
    5 + 55 + 5 Addition 加成
    5 - 55 - 5 Subtraction 减法
    10 / 210 / 2 Division
    5 * 25 * 2 Multiplication 乘法
    3 ** 23 ** 2 3 to the power of 3提高到2 (or )2 (或)的幂
    27 ** (1/3)27 ** (1/3) 3rd root of 27 (或)的第27 (or )3
    x += 1x += 1 x + 1 to x + 1的值分配给xx
    x -= 1x -= 1 x - 1 to x - 1的值分配给xx

    清单 (Lists)

    l = [100, 21, 88, 3]l = [100, 21, 88, 3] 100, 10021, 2188, and 88 ,和3 to the variable 3至可变ll
    l = list()l = list() ll
    l[0]l[0] ll
    l[-1]l[-1] ll
    l[1:3]l[1:3] ll的第二个和第三个值的切片(列表)
    len(l)len(l) ll的元素数
    sum(l)sum(l) ll的值之和
    min(l)min(l) ll返回最小值
    max(l)max(l) ll返回最大值
    l.append(16)l.append(16) 16 to the end of 16附加到ll的末尾
    l.sort()l.sort() l in ascending orderl中的项目进行排序
    " ".join(["A", "B", "C", "D"])" ".join(["A", "B", "C", "D"]) ["A", "B", "C", "D"] into the string ["A", "B", "C", "D"]转换为字符串"A B C D""ABCD"

    辞典 (Dictionaries)

    d = {"CA": "Canada", "GB": "Great Britain", "IN": "India"}d = {"CA": "Canada", "GB": "Great Britain", "IN": "India"} "CA", "CA""GB", and "GB""IN" and corresponding values of of "IN"以及"Canada", "Canada""Great Britain", and "Great Britain""India""India"对应值创建字典
    d["GB"]d["GB"] d that has the key d中返回具有键"GB""GB"
    d.get("AU","Sorry")d.get("AU","Sorry") d that has the key d具有关键"AU", or the string "AU"或字符串"Sorry" if the key "Sorry"如果键"AU" is not found in "AU"中找不到dd
    d.keys()d.keys() dd返回键列表
    d.values()d.values() dd的值列表
    d.items()d.items() (key, value) pairs from d返回d(key, value)对的列表

    模块和功能 (Modules and Functions)

    The body of a function is defined through indentation

    函数的主体通过缩进定义

    import randomimport random randomrandom导入模块
    from random import randomfrom random import random random from the module random从模块randomrandom
    calculate with two required and two optional named arguments which calculates and returns a result.calculate ,该参数计算并返回结果。
    addition(3,5,factor=10)addition(3,5,factor=10) addition function with the values 33 and 5以及命名参数5 and the named argument 10运行10addition函数

    布尔比较 (Boolean Comparisons)

    x == 5x == 5 x is equal to x是否等于55
    x != 5x != 5 x is not equal to x是否等于55
    x > 5x > 5 x is greater than x是否大于55
    x < 5x < 5 x is less than x是否小于55
    x >= 5x >= 5 x is greater than or equal to x是否大于或等于55
    x <= 5x <= 5 x is less than or equal to x是否小于或等于55
    x == 5 or name == "alfred"x == 5 or name == "alfred" x is equal to x是否等于5 or 5name is equal to name等于"alfred""alfred"
    x == 5 and name == "alfred"x == 5 and name == "alfred" x is equal to x是否等于5 and 5并且name is equal to name是否等于"alfred""alfred"
    5 in l5 in l 5 exists in the list l是否存在值l5
    "GB" in d"GB" in d "GB" exists in the keys for d的键中是否存在值d"GB"

    语句和循环 (Statements and Loops)

    The body of if statements and loops are defined through indentation

    if语句和循环的主体是通过缩进定义的

    if x > 5:
        print("{} is greater than five".format(x))
    elif x < 0:
        print("{} is negative".format(x))
    else:
        print("{} is between zero and five".format(x))
    if x > 5:
        print("{} is greater than five".format(x))
    elif x < 0:
        print("{} is negative".format(x))
    else:
        print("{} is between zero and five".format(x))
    
    x and run the code body based on the valuex的值并基于该值运行代码主体
    l, running the code in the body of the loop with each iteration.l每个值,并在每次迭代时在循环体内运行代码。
    while x < 10:
        x += 1
    while x < 10:
        x += 1
    
    x is no longer less than x的值不再小于1010

    下载此备忘单的可打印版本 (Download a printable version of this cheat sheet)

    翻译自: https://www.pybloggers.com/2017/07/python-cheat-sheet-for-data-science/

    python 桌面备忘录

    展开全文
  • Python学习备忘录

    2021-03-12 15:53:37
    1. pip 更新报错 换成下面这行代码 python -m pip install -U --force-reinstall pip

    目录

    1. pip 更新报错

    2.Jupyter Notebook缺包

    3.缺urllib2包


    1. pip 更新报错

    • 换成下面这行代码
    python -m pip install -U --force-reinstall pip

    2.Jupyter Notebook缺包

    • 打开cmd
    conda info --env
    • 激活环境,如:
    activate base
    • 最后安装模块
    pip install XX
    • 也可以使用清华镜像
    pip install XX -i https://pypi.tuna.tsinghua.edu.cn/simple

    3.缺urllib2包

    • 在python中,用urllib.request代替urllib2
    import urllib.request

     

    展开全文
  • alist = ['a',1,2] random.choice(alist) Out[7]: 2
  • # 判断小数部分是否为 0 float.is_integer() (3.0).is_integer() # True # 十進制格式转换为十六進制格式 float.hex() (3.2).hex() # '0x1.999999999999ap+1' ...float.fromhex('0xFF.FFFFp3') # 2047....

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 7,764
精华内容 3,105
关键字:

python写备忘录

python 订阅