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)
  • 相关阅读:
    云计算分布式大数据神器Spark实战高手之旅
    Spring IOC及AOP学习总结
    Win7下不能查看xp系统共享的文件,解决方法
    c#怎样获取excel单元格的RGB颜色
    MySQL 全角转换为半角
    【剑指offer】旋转数组的最小值
    POJ 2524 :Ubiquitous Religions
    GitLal+sourceTree版本号管理
    ASP.NET MVC 过滤器(五)
    Java设计模式之观察者模式
  • 原文地址:https://www.cnblogs.com/xkxf/p/8196558.html
Copyright © 2011-2022 走看看