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)
  • 相关阅读:
    jQuery如何获取选中单选按钮radio的值
    java计算出字符串中所有的数字求和?
    java 多线程对List中的数据进行操作
    MongoDB
    CentOS网卡一致性命名
    linux之list_for_each和list_for_each_entry函数
    linux开机启动项
    linux学习参考网站
    linux内核态获取纳秒ns时间
    Linux内核kfifo
  • 原文地址:https://www.cnblogs.com/xkxf/p/8196558.html
Copyright © 2011-2022 走看看