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)
  • 相关阅读:
    jvm调优核心思路
    G1 垃圾回收器
    类加载和内存区域划分
    jvm优化案例
    垃圾回收
    buffer pool详解
    InnoDb存储引擎执行流程
    mysql总体架构
    (转载)C#串口介绍以及简单串口通信程序设计实现
    C++文本操作(读写文本文件/二进制文件)
  • 原文地址:https://www.cnblogs.com/xkxf/p/8196558.html
Copyright © 2011-2022 走看看