zoukankan      html  css  js  c++  java
  • Python笔记 #03# Help!

    源:DataCamp

    datacamp 的 DAILY PRACTICE  + 日常收集。

    Functions

    Built-in functions

    Help!

    Multiple arguments

    Functions

    By now, you have an idea about how to use max() and round(), but how could you know that a function such as round() exists in Python in the first place? Well, this is something you will learn with time. Whenever you are doing a rather standard task in Python, you can be pretty sure that thers is already a function that can do this for you. In that case, you should definitely use it! Just do a quick internet search and you will find the function you need with a nice usage example!

    Built-in functions

    # Create variables var1 and var2
    var1 = [1, 2, 3, 4]
    var2 = True
    
    # Print out type of var1
    print(type(var1))
    
    # Print out length of var1
    print(len(var1))
    
    # Convert var2 to an integer: out2
    out2 = int(var2)

    Help!

    Maybe you already know the name of a Python function, but you still have to figure out how to use it. Ironically, you have to ask for information about a function with another function: help()

    To get help on the max() function, for example, you can use one of these calls:

    help(max)
    ?max

    Use the Shell on the right to open up the documentation on complex(). Which of the following statements is true?

    Multiple arguments

    Have a look at the documentation of sorted() by typing help(sorted) in the IPython Shell.

    You'll see that sorted() takes three arguments: iterablekey and reverse.

    key=None means that if you don't specify the keyargument, it will be Nonereverse=False means that if you don't specify the reverse argument, it will be False.

    In this exercise, you'll only have to specify iterable and reverse, not key. The first input you pass to sorted()will be matched to the iterable argument, but what about the second input? To tell Python you want to specify reverse without changing anything about key, you can use =:

    sorted(___, reverse = ___)
    # Create lists first and second
    first = [11.25, 18.0, 20.0]
    second = [10.75, 9.50]
    
    # Paste together first and second: full
    full = first + second
    
    # Sort full in descending order: full_sorted
    full_sorted = sorted(full, reverse=True)
    
    # Print out full_sorted
    print(full_sorted)
  • 相关阅读:
    centos 7 pip install MySQL-python 报错
    修改centos history记录数上限
    CentOS 7 如何设置为eth0网卡
    字符串判空有空格报错:binary operator expected
    Linux指定用户运行程序
    MySQL 新建用户,为用户授权,指定用户访问数据库
    解决linux 中文乱码
    UNIX目录访问操作
    通过lseek产生空洞文件
    lseek系统调用
  • 原文地址:https://www.cnblogs.com/xkxf/p/8196558.html
Copyright © 2011-2022 走看看