Python笔记 #03# Help!
源:DataCamp
datacamp 的 DAILY PRACTICE + 日常收集。
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: iterable
, key
and reverse
.
key=None
means that if you don't specify the key
argument, it will be None
. reverse=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)
Python笔记 #03# Help!的更多相关文章
- 我的Python笔记03
摘要: 声明:本文整理借鉴金角大王的Python之路,Day3 - Python基础3,仅供本人学习使用!!! 本节内容 1. 函数基本语法及特性 2. 参数与局部变量 3. 返回值 嵌套函数 4 ...
- python笔记03:使用字符串
3.1 基本字符串操作: 所有的标准序列操作(索引,分片,乘法,判断成员资格,求长度,取最小值,取最大值)对于字符串同样有效.但是,请记住:字符串都是不可变的 3.2 字符串格式化:精简版 字符串格式 ...
- python笔记03
day03 一.今日内容: 1.整型 2.字符串 3.布尔类型 二.内容回顾和补充 脑图--xmind软件,processon 1.运算符补充(in.not in) value = "我是中 ...
- python笔记 - day6
python笔记 - day6 参考: http://www.cnblogs.com/wupeiqi/articles/5501365.html 大纲: 利用递归,实现阶乘: Python反射 pyt ...
- python笔记之常用模块用法分析
python笔记之常用模块用法分析 内置模块(不用import就可以直接使用) 常用内置函数 help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像 ...
- python笔记-1(import导入、time/datetime/random/os/sys模块)
python笔记-6(import导入.time/datetime/random/os/sys模块) 一.了解模块导入的基本知识 此部分此处不展开细说import导入,仅写几个点目前的认知即可.其 ...
- 机器学习实战(Machine Learning in Action)学习笔记————03.决策树原理、源码解析及测试
机器学习实战(Machine Learning in Action)学习笔记————03.决策树原理.源码解析及测试 关键字:决策树.python.源码解析.测试作者:米仓山下时间:2018-10-2 ...
- OpenCV 学习笔记03 findContours函数
opencv-python 4.0.1 1 函数释义 词义:发现轮廓! 从二进制图像中查找轮廓(Finds contours in a binary image):轮廓是形状分析和物体检测和识别的 ...
- Python笔记之不可不练
如果您已经有了一定的Python编程基础,那么本文就是为您的编程能力锦上添花,如果您刚刚开始对Python有一点点兴趣,不怕,Python的重点基础知识已经总结在博文<Python笔记之不可不知 ...
随机推荐
- 实现 IteratorAggregate接口
<?php class MyIterator implements Iterator{ private $var = array(); public function __construct($ ...
- std::ostringstream
ostringstream是C++的一个字符集操作模板类,定义在sstream.h头文件中.ostringstream类通常用于执行C风格的串流的输出操作,格式化字符串,避免申请大量的缓冲区,替代sp ...
- android签名,制作key
签名具体步骤: Apk签名首先要有一个keystore的签名用的文件. keystore是由jdk自带的工具keytool生成的.具体生成方式参考一下: 开始->运行->cmd->c ...
- java enum(枚举)使用详解 + 总结(转载)
enum 的全称为 enumeration, 是 JDK 1.5 中引入的新特性,存放在 java.lang 包中. 下面是我在使用 enum 过程中的一些经验和总结,主要包括如下内容: 1. 原始 ...
- java面向对象基础回顾
(49) (0) 面向对象 啥是面向对象 什么是多态多态的机制 接口和抽象类区别 个人理解 代码实现 面向对象 学习java大家接触到的最多的话语无非就是面向对象,可能大家没有仔细研究过这个问题,但 ...
- Spring 拦截器的使用
一.Web.xml配置 在Web.xml 配置Spring核心控制器DispatcherServlet接收所有请求 <servlet> <servlet-name>spring ...
- hdu4686 简单的矩阵快速幂求前n项和
HDU4686 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意:题目说的很清楚了,英语不好的猜也该猜懂了,就是求一个表达式的前n项和,矩阵 ...
- Markdown安装与简单使用
早就听过Markdown的大名了,说是最适合程序员的编辑器,一点也不为过.平时写文章,写博客.除了内容以外,还要被一堆繁琐的样式困扰,毕竟样式太难看,既是自己的文章,也会懒得看的.今天正好看到博客上面 ...
- Linux下的物理内存管理2-slab缓存的管理
2017-03-02 在Linux下的物理内存管理中,对SLAB机制大致做了介绍,对SLAB管理结构对象也做了介绍,但是对于小内存块的分配没有介绍,本节重点介绍下slab对小内存块的管理. 内核中使用 ...
- Python的编码问题(一)
一.什么是编码 可以说,计算机是一个即聪明又笨蛋的家伙.说它聪明,是因为他可以做很多事情,它的强大无需多说,大家应该都有所了解以及感受.但是为什么说它又是个笨蛋呢,因为我们在电脑上写出的每一个字,保存 ...