一、数学相关
1、绝对值:abs(-1)
2、最大最小值:max([1,2,3])、min([1,2,3])
3、序列长度:len('abc')、len([1,2,3])、len((1,2,3))
4、取模:divmod(5,2)//(2,1)
5、乘方:pow(2,3,4)//2**3/4
6、浮点数:round(1)//1.0
二、功能相关
1、函数是否可调用:callable(funcname),注意,funcname变量要定义过
2、类型判断:isinstance(x,list/int)
3、比较:cmp('hello','hello')
4、快速生成序列:(x)range([start,] stop[, step])
三、类型转换
1、int(x)
2、long(x)
3、float(x)
4、complex(x) //复数
5、str(x)
6、list(x)
7、tuple(x) //元组
8、hex(x)
9、oct(x)
10、chr(x)//返回x对应的字符,如chr(65)返回‘A'
11、ord(x)//返回字符对应的ASC码数字编号,如ord('A')返回65
四、字符串处理
1、首字母大写:str.capitalize
代码如下:
>>> 'hello'.capitalize()
'Hello'
2、字符串替换:str.replace
代码如下:
>>> 'hello'.replace('l','2')
'he22o'
可以传三个参数,第三个参数为替换次数
3、字符串切割:str.split
代码如下:
>>> 'hello'.split('l')
['he', '', 'o']
可以传二个参数,第二个参数为切割次数
以上三个方法都可以引入String模块,然后用string.xxx的方式进行调用。
五、序列处理函数
1、len:序列长度
2、max:序列中最大值
3、min:最小值
4、filter:过滤序列
代码如下:
>>> filter(lambda x:x%2==0, [1,2,3,4,5,6])
[2, 4, 6]
5、zip:并行遍历
代码如下:
>>> name=['jim','tom','lili']
>>> age=[20,30,40]
>>> tel=['133','156','189']
>>> zip(name,age,tel)
[('jim', 20, '133'), ('tom', 30, '156'), ('lili', 40, '189')]
注意,如果序列长度不同时,会是下面这样的结果:
代码如下:
>>> name=['jim','tom','lili']
>>> age=[20,30,40]
>>> tel=['133','170']
>>> zip(name,age,tel)
[('jim', 20, '133'), ('tom', 30, '170')]
6、map:并行遍历,可接受一个function类型的参数
代码如下:
>>> a=[1,3,5]
>>> b=[2,4,6]
>>> map(None,a,b)
[(1, 2), (3, 4), (5, 6)]
>>> map(lambda x,y:x*y,a,b)
[2, 12, 30]
7、reduce:归并
代码如下:
>>> l=range(1,101)
>>> l
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
>>> reduce(lambda x,y:x+y,l)
5050

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.