`
MyEyeOfJava
  • 浏览: 1124403 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
7af2d6ca-4fe1-3e9a-be85-3f65f7120bd0
测试开发
浏览量:70159
533896eb-dd7b-3cde-b4d3-cc1ce02c1c14
晨记
浏览量:0
社区版块
存档分类
最新评论

python3常见操作

阅读更多

 

 布尔操作,是或者否:

Operation

Result

Notes

x or y

if x is false, then y, else x

(1)

x and y

if x is false, then x, else y

(2)

not x

if x is false, then True, else False

(3)

 

 

比较操作,大还是小,是否相同对象,是否相同值:

Operation

Meaning

<

strictly less than

<=

less than or equal

>

strictly greater than

>=

greater than or equal

==

equal

!=

not equal

is

object identity

is not

negated object identity

 

 

常用数学计算:

Operation

Result

Notes

Full documentation

x + y

sum of x and y

   

x - y

difference of x and y

   

x * y

product of x and y

   

x / y

quotient of x and y

   

x // y

floored quotient of x and y

(1)

 

x % y

remainder of x / y

(2)

 

-x

x negated

   

+x

x unchanged

   

abs(x)

absolute value or magnitude of x

 

abs()

int(x)

x converted to integer

(3)(6)

int()

float(x)

x converted to floating point

(4)(6)

float()

complex(re, im)

a complex number with real part re, imaginary part imim defaults to zero.

(6)

complex()

c.conjugate()

conjugate of the complex number c

   

divmod(x, y)

the pair (x // y, x % y)

(2)

divmod()

pow(x, y)

x to the power y

(5)

pow()

x ** y

x to the power y

(5)

 

 

字符串常见操作:

Operation

Result

Notes

x in s

True if an item of s is equal to x, else False

(1)

x not in s

False if an item of s is equal to x, else True

(1)

s + t

the concatenation of s and t

(6)(7)

s * n or n * s

equivalent to adding s to itself n times

(2)(7)

s[i]

ith item of s, origin 0

(3)

s[i:j]

slice of s from i to j

(3)(4)

s[i:j:k]

slice of s from i to j with step k

(3)(5)

len(s)

length of s

 

min(s)

smallest item of s

 

max(s)

largest item of s

 

s.index(x[, i[, j]])

index of the first occurrence of x in s (at or after index i and before index j)

(8)

s.count(x)

total number of occurrences of x in s

 

 

 

数组常见操作:

Operation

Result

Notes

s[i] = x

item i of s is replaced by x

 

s[i:j] = t

slice of s from i to j is replaced by the contents of the iterable t

 

del s[i:j]

same as s[i:j] = []

 

s[i:j:k] = t

the elements of s[i:j:k] are replaced by those of t

(1)

del s[i:j:k]

removes the elements of s[i:j:k]from the list

 

s.append(x)

appends x to the end of the sequence (same as s[len(s):len(s)] = [x])

 

s.clear()

removes all items from s (same as del s[:])

(5)

s.copy()

creates a shallow copy of s (same as s[:])

(5)

s.extend(t) or s += t

extends s with the contents of t (for the most part the same ass[len(s):len(s)] = t)

 

s *= n

updates s with its contents repeated n times

(6)

s.insert(i, x)

inserts x into s at the index given by i(same as s[i:i] = [x])

 

s.pop([i])

retrieves the item at i and also removes it from s

(2)

s.remove(x)

remove the first item from s where s[i] is equal to x

(3)

s.reverse()

reverses the items of s in place

(4)

 

 

常见格式化占位符:

Conversion

Meaning

Notes

'd'

Signed integer decimal.

 

'i'

Signed integer decimal.

 

'o'

Signed octal value.

(1)

'u'

Obsolete type – it is identical to 'd'.

(6)

'x'

Signed hexadecimal (lowercase).

(2)

'X'

Signed hexadecimal (uppercase).

(2)

'e'

Floating point exponential format (lowercase).

(3)

'E'

Floating point exponential format (uppercase).

(3)

'f'

Floating point decimal format.

(3)

'F'

Floating point decimal format.

(3)

'g'

Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.

(4)

'G'

Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.

(4)

'c'

Single character (accepts integer or single character string).

 

'r'

String (converts any Python object using repr()).

(5)

's'

String (converts any Python object using str()).

(5)

'a'

String (converts any Python object using ascii()).

(5)

'%'

No argument is converted, results in a '%' character in the result.

 
分享到:
评论

相关推荐

    Python操作常见Office软件.zip - Python 操作 Excel、Word、Pdf 等

    Python操作常见Office软件.zip - Python 操作 Excel、Word、Pdf 等。Python操作常见Office软件.zip - Python 操作 Excel、Word、Pdf 等。Python操作常见Office软件.zip - Python 操作 Excel、Word、Pdf 等。Python...

    python不常见的字符串操作.txt

    python的一些字符串的不常见操作哦!相信大家都用惯了那些常见的字符串操作,想学一些不常见,但是有可能用得到的操作吧!看这里,你值得拥有

    Python经典面试题 Python常见面试考试题目整理总结 Python面试题手册 共15页.pdf

    Python经典面试题 Python常见面试考试题目整理总结 Python面试题手册 1:Python 如何实现单例模式? 2:什么是 lambda 函数? 3:Python 是如何进行类型转换的? 4:Python 如何定义一个函数 5:Python 是如何进行...

    opencv-python常见操作

    本资源为opencv-python的python文件,主要包含常用的opencv-python的相关操作,可以用于初学者的学习以及快速进行开发。

    Python3入门指南_v2.4.pdf

    这是DS小龙哥编写整理的,Python3入门指南.pdf,总共10章,可以当做入门书籍、平时的参考书籍,文中代码都可以复制粘贴。后续资源包会持续更新。 这是书籍的目录 编辑: DS小龙哥 1 Python3入门指南 1 一、 Python...

    python常见的文件和文件夹操作

    内容概要:python常见的文件和文件夹操作 目标人群:具有一定python编程基础的人群 使用场景:Python3 功能介绍:显示当前工作目录下的所有文件名和文件夹名、显示当前工作目录下的所有文件的大小总和等。

    pythonnumpy教程-PythonNumpy库常见用法入门教程.pdf

    pythonnumpy教程_PythonNumpy库常见⽤法⼊门教程 本⽂实例讲述了Python Numpy库常见⽤法。分享给⼤家供⼤家参考,具体如下: 1、简介 Numpy是⼀个常⽤的Python科学技术库,通过它可以快速对数组进⾏操作,包括形状...

    用Python 完成常见的任务

    我们将介绍Python 程 序员要面对的常见的任务。这些任务分为 —— 数据结构操作,文件操作等等。

    2024年非常全面的100道Python常见基础面试题

    本教程包含了100个常见的Python面试题,涵盖Python基础知识、高级特性、网络编程、数据库操作、数据结构和算法等多个方面。每个问题都提供了详细的解析,帮助面试者更好地准备Python面试。 适用人群: 本教程适合...

    python常见字符换的操作技巧

    python常见字符换的操作技巧,适合初学者学习

    Python常见面试题精讲

    Python常见面试题精讲,请诸位认真操作,预祝诸位顺利通过

    Python Numpy库常见用法入门教程

    本文实例讲述了Python Numpy库常见用法。分享给大家供大家参考,具体如下: 1、简介 Numpy是一个常用的Python科学技术库,通过它可以快速对数组进行操作,包括形状操作、排序、选择、输入输出、离散傅立叶变换、基本...

    Python元组常见操作示例

    主要介绍了Python元组常见操作,结合实例形式分析了Python元组的概念、功能、常见定义、获取、遍历等相关操作技巧与注意事项,需要的朋友可以参考下

    Python OS模块(常见文件操作示例).doc

    Python

    python常见数据类型.docx

    python常见数据类型 Python是一种高级编程语言,它支持多种数据类型,包括数字、字符串、列表、元组、字典和集合。在本文中,我们将介绍这些常见的Python数据类型。 数字 Python支持三种数字类型:整数、浮点数和...

    Python文件常见操作实例分析【读写、遍历】

    主要介绍了Python文件常见操作,结合实例形式分析Python针对文件的读写、遍历等相关操作技巧,需要的朋友可以参考下

    用python完成常见任务

    现在,我们已学习了Python 的语法,它的基本的数据类型,和很多我们喜欢的 Python 的库函数。本章假设你至少理解了这门语言的所有基本成分,并且除了 ...这些任务分为—— 数据结构操作,文件操作等等。

    在常见操作系统上安装 Python 的简单教程

    在常见操作系统上安装 Python 的简单教程

Global site tag (gtag.js) - Google Analytics