Python 2.5 Reference Card
根据提供的文件信息,我们可以从标题、描述以及部分内容中提取出一系列与Python 2.5相关的知识点。虽然标签中出现了一些与Python无关的技术(如ASP.NET、Java、J2EE、Visual Studio、C++),但本篇文章将专注于Python 2.5本身的内容。 ### Python 2.5 Reference Card #### 1. Variable Types ##### 1.1 Numbers - **Integer and Long Integers:** - `42`: A regular integer. - `052`: An octal representation (equivalent to decimal 42). - `0x2A`: A hexadecimal representation (also equivalent to decimal 42). - `42L`: A long integer (Python 2.5 uses different types for integers and long integers). - **Floating Point Values:** - `0.2`: A floating-point number. - `1.0e-7`: Scientific notation for floating-point numbers. - **Complex Numbers:** - `5.0-2.0j`: A complex number with real part 5.0 and imaginary part -2.0. - `complex(real, imag)`: Constructor for creating complex numbers from real and imaginary parts. - `z.real` and `z.imag`: Attributes to access the real and imaginary parts of a complex number. - **Boolean Values:** - `True` and `False`: Constants representing boolean values. - **Numeric Operations:** - `abs(n)`: Absolute value function. - `divmod(x, y)`: Returns a tuple containing the quotient and remainder of division. - `hex(n)` and `oct(n)`: Convert an integer to its hexadecimal or octal string representation. - `ord(c)`: Returns the Unicode code point of a character. - `round(x, n)`: Rounds a number to `n` decimal places. - `cmp(x, y)`: Compares two numbers (`-1` if `x < y`, `0` if `x == y`, and `1` if `x > y`). - `coerce(x, y)`: Converts both operands to the same type. - `pow(x, y, z)`: Computes `(x ** y) % z`. - `float("3.14")`: Converts a string to a floating-point number. - `int("42", base)`: Converts a string to an integer, using the specified base. - **Additional Math Functions:** - `import math`: Standard math functions such as `sin`, `cos`, etc. - `import cmath`: Complex math functions. - **Random Number Generation:** - `import random`: Functions for generating random numbers. ##### 1.2 Sequences (Lists are mutable, Tuples and Strings are immutable) - **List Creation:** - `s = l = [1, "bla", [1+2j, 1.4], 4]`: Creates a list with various elements including another list. - **Tuple Creation:** - `s = t = (1, "bla", [1+2j, 1.4], 4)`: Creates a tuple with various elements including a list. - **List/Tuple Conversion:** - `l = list(t)`: Converts a tuple to a list. - `t = tuple(l)`: Converts a list to a tuple. - **Range and XRange:** - `l = range(1000)`: Creates a list of integers from 0 to 999. - `s = xrange(1000)`: Creates an immutable sequence object that represents the range. - **Iterator:** - `i = iter(s)`: Creates an iterator from a sequence. - `i.next()`: Retrieves the next item from the iterator. - **Accessing Elements:** - `s[2][0]`: Accesses the first element of the nested list within the main list. - `s[-2][-1]`: Accesses the last element of the second-to-last element in the list. - **Sequence Operations:** - `s1 + s2`: Concatenates two sequences. - `n * s1`: Repeats the sequence `n` times. - `s[i:j]`: Slices the sequence from index `i` to `j-1`. - `s[i:j:k]`: Slices the sequence with stride `k`. - `s[::2]`: Every second element. - `s[::-1]`: Reverses the sequence. - **Membership Testing:** - `x in s`: Checks if `x` is a member of the sequence `s`. - **List Manipulation:** - `len(s)`: Returns the number of elements in the sequence. - `min(s)` and `max(s)`: Returns the minimum and maximum elements in the sequence. - `l[i:j] = ['a', 'b', 'c', 'd']`: Replaces a slice with new values. - `l[i:i] = ['a', 'b']`: Inserts elements before position `i`. - `l.count(x)`: Counts the occurrences of `x` in the list. - `l.index(x)`: Finds the index of the first occurrence of `x`. - `l.append(x)`: Appends `x` to the end of the list. - `x = l.pop()`: Removes and returns the last element of the list. - `l.extend(l2)`: Appends all elements of `l2` to the end of `l`. - `l.insert(i, x)`: Inserts `x` at position `i`. - `l.remove(x)`: Removes the first occurrence of `x`. - `l.reverse()`: Reverses the list in place. - `l.sort(f)`: Sorts the list using the comparison function `f` (default is `cmp`). - **Dictionary Operations:** - `d = {'x': 42, 'y': 3.14, 'z': 7}`: Creates a dictionary. - `d['x']`: Retrieves the value associated with the key `'x'`. - `len(d)`: Returns the number of keys in the dictionary. - `del d['x']`: Deletes the entry for the key `'x'`. - `d.copy()`: Creates a shallow copy of the dictionary. 以上内容涵盖了Python 2.5中变量类型的详细介绍,包括数值类型的操作、序列的处理以及字典的基本操作。这些知识点对于理解和使用Python 2.5版本的编程语言非常关键。
- 粉丝: 238
- 资源: 1609
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于C语言的系统服务框架.zip
- (源码)基于Spring MVC和MyBatis的选课管理系统.zip
- (源码)基于ArcEngine的GIS数据处理系统.zip
- (源码)基于JavaFX和MySQL的医院挂号管理系统.zip
- (源码)基于IdentityServer4和Finbuckle.MultiTenant的多租户身份认证系统.zip
- (源码)基于Spring Boot和Vue3+ElementPlus的后台管理系统.zip
- (源码)基于C++和Qt框架的dearoot配置管理系统.zip
- (源码)基于 .NET 和 EasyHook 的虚拟文件系统.zip
- (源码)基于Python的金融文档智能分析系统.zip
- (源码)基于Java的医药管理系统.zip