Python关键函数
2016-06-17 15:37
615 查看
1.字符串函数
str1='string'
str1.upper() #全部转换为大写
str1.isalpha() #是否全部是字母
str1.lower() #全部转换为小写
len(str1) 长度
str(str1) 将任意字符转换为字符串
2.数学函数The
returns the absolute
value of the number it takes as an
argument—that is, that number's distance
from
an imagined number line. For
instance,
have the same absolute value:
The
always returns a positive value, and
unlike
it only takes a single number.Finally, the
returns the typeof
the data it receives as an argument. If you ask Python to do the
following:
[/code]Python will output:
[/code]
[/code]
[/code]
[/code]
remove the item at
the list and return it to you:
[/code]
actual
it finds it:
[/code]
like
that it will remove the item at the given index, but it won't
return it:
[/code]
序列求和可直接用内建的sum(序列名称)函数enumerate函数choices = ['pizza', 'pasta', 'salad', 'nachos']print 'Your choices are:'for index, item in enumerate(choices): print
index+1, item zip()函数:该函数可以将两个序列配对。例如list_a = [3, 9, 17, 15, 19]list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90],那么print
zip(list_a, list_b)之后的结果为[(3,2),(9,4),(17,8),(15,10)(19,30)]
[/code]
str1='string'
str1.upper() #全部转换为大写
str1.isalpha() #是否全部是字母
str1.lower() #全部转换为小写
len(str1) 长度
str(str1) 将任意字符转换为字符串
2.数学函数The
abs()function
returns the absolute
value of the number it takes as an
argument—that is, that number's distance
from
0on
an imagined number line. For
instance,
3and
-3both
have the same absolute value:
3.
The
abs()function
always returns a positive value, and
unlike
max()and
min(),
it only takes a single number.Finally, the
type()function
returns the typeof
the data it receives as an argument. If you ask Python to do the
following:
[code]print type(42) print type(4.2) print type('spam')
[/code]Python will output:
[code]'int'> 'float'> 'str'>
[/code]
[code]3.序列函数:
[/code]
[code]append()
[/code]
animals = ["ant", "bat", "cat"] print animals.index("bat")
This exercise will expand on ways to remove items from a list. You actually have a few options. For a list called[code]n:
[/code]
n.pop(index)will
remove the item at
indexfrom
the list and return it to you:
[code]n = [
[/code]
n.remove(item)will remove the
actual
itemif
it finds it:
[code]n.remove(
[/code]
del(n[1])is
like
.popin
that it will remove the item at the given index, but it won't
return it:
[code]
[/code]
nts " d = {"foo" : "bar"}for key in d:
print d[key] # prints
ar"
序列求和可直接用内建的sum(序列名称)函数enumerate函数choices = ['pizza', 'pasta', 'salad', 'nachos']print 'Your choices are:'for index, item in enumerate(choices): print
index+1, item zip()函数:该函数可以将两个序列配对。例如list_a = [3, 9, 17, 15, 19]list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90],那么print
zip(list_a, list_b)之后的结果为[(3,2),(9,4),(17,8),(15,10)(19,30)]
[code]d = {
[/code]
相关文章推荐
- PHP与Python对比
- Running Python CGI Scripts on IIS(Windows操作系统,在IIS上运行Python)
- Python多线程、异步+多进程爬虫实现代码
- python支持多线程的爬虫
- 零基础写python爬虫之使用Scrapy框架编写爬虫
- eclipse中python插件安装
- 把玩之python爬虫cookie篇
- Python Tricks(十七)—— enumerate 的实现
- 搭建本地Python Package Index(pypi)源
- 重新安装python时出现的问题
- Python list 基础知识篇
- Python 小练习 出差费用
- Python应用科学计算和图表绘制
- python日志操作(loggin模块)
- python os模块文件目录
- [每日一课】 Python官方文档--- 函数进阶
- 美团多渠道打包方案详解,速度快到白驹过隙
- python微教程---第一季(第二集)----基础知识(让python运行起来)
- python获取页面元素的内容及长度
- 三、Python运算符与表达式