`
provista
  • 浏览: 120474 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Python Tips (2)

阅读更多
类型转换
函数                      描述
int(x [,base ])         将x转换为一个整数
long(x [,base ])        将x转换为一个长整数
float(x )               将x转换到一个浮点数
complex(real [,imag ])  创建一个复数
str(x )                 将对象 x 转换为字符串
repr(x )                将对象 x 转换为表达式字符串
eval(str )              用来计算在字符串中的有效Python表达式,并返回一个对象
tuple(s )               将序列 s 转换为一个元组
list(s )                将序列 s 转换为一个列表
chr(x )                 将一个整数转换为一个字符
unichr(x )              将一个整数转换为Unicode字符
ord(x )                 将一个字符转换为它的整数值
hex(x )                 将一个整数转换为一个十六进制字符串
oct(x )                 将一个整数转换为一个八进制字符串


序列操纵
操作                      描述   
s + r                   序列连接   
s * n , n * s           s的 n 次拷贝,n为整数   
s % d                   字符串格式化(仅字符串)   
s[i]                    索引   
s[i :j ]                切片   
x in s , x not in s     从属关系   
for x in s :            迭代   
len(s)                  长度   
min(s)                  最小元素   
max(s)                  最大元素   
s[i ] = x               为s[i]重新赋值   
s[i :j ] = r            将列表片段重新赋值   
del s[i ]               删除列表中一个元素   
del s[i :j ]            删除列表中一个片段  

操作                      描述
s + r                   序列连接
s * n , n * s           s的 n 次拷贝,n为整数
s % d                   字符串格式化(仅字符串)
s[i]                    索引
s[i :j ]                切片
x in s , x not in s     从属关系
for x in s :            迭代
len(s)                  长度
min(s)                  最小元素
max(s)                  最大元素
s[i ] = x               为s[i]重新赋值
s[i :j ] = r            将列表片段重新赋值
del s[i ]               删除列表中一个元素
del s[i :j ]            删除列表中一个片段

数值计算
x << y                  左移   
x >> y                  右移   
x & y                   按位与   
x | y                   按位或   
x ^ y                   按位异或 (exclusive or)   
~x                      按位翻转   
x + y                   加   
x - y                   减   
x * y                   乘   
x / y                   常规除   
x // y                  地板除   
x ** y                  乘方 (xy )   
x % y                   取模 (x mod y )   
-x                      改变操作数的符号位   
+x                      什么也不做   
~x                      ~x=-(x+1)   
abs(x )                 绝对值   
divmod(x ,y )           返回 (int(x / y ), x % y )   
pow(x ,y [,modulo ])    返回 (x ** y ) x % modulo   
round(x ,[n])           四舍五入,n为小数点位数   
x < y                   小于   
x > y                   大于   
x == y                  等于   
x != y                  不等于(与<>相同)   
x >= y                  大于等于   
x <= y                  小于等于  
分享到:
评论

相关推荐

    Python-PythonTips一些初学者到中级用户的Python技巧

    Python Tips 一些初学者到中级用户的Python技巧

    python-tips-tricks:Python技巧与窍门

    Python技巧与窍门有关Python的一些技巧和窍门。有用的文件-BeautifulSoup库的概述,以便解析XML文件。 -概述Oletools库,以便检查VB代码 -Pyspark库概述-Sweetviz库概述帮助您找到所有缺少的值并显示它们-获取文件的...

    五个Python编程Tips,帮你提高编码效率.doc

    五个Python编程Tips,帮你提高编码效率.doc

    Python.Unit.Test.Automation.pdf

    Quickly learn how to automate unit testing of Python 3 code with Python 3 automation libraries, such as doctest, unittest, nose, nose2, and pytest. This book explores the important concepts in ...

    Data-Wrangling-with-Python-Tips-and-Tools-to-Make-Your-Life-Easier.pdf.pdf

    Data-Wrangling-with-Python-Tips-and-Tools-to-Make-Your-Life-Easier.pdf

    Illustrated Guide to Python 3

    Packed with Useful Hints and Tips You'll learn the best practices without wasting time searching or trying to force Python to be like other languages. I've collected all the gems I've gleaned over ...

    Serious Python

    An indispensable collection of practical tips and real-world advice for tackling common Python problems and taking your code to the next level. Features interviews with high-profile Python developers ...

    tips.txt为python数据分析案例数据

    python数据分析案例数据 主要用于本人博客的部分文章案例数据使用。 单变量的样本分布检验(python3) 探索变量间关系 ....... 等文章的案例数据

    Clean Python.pdf

    The main goal of this book is to provide tips to Python developers of various levels so they can write better Python software and programs. This book gives you various techniques irrespective of the ...

    英文原版-Programming Python Programming Guide For Beginners Learn In a Day 2nd Edition

    These fun and easy tips transform the dreaded chore of learning a new programming language into a fun process. You'll be proud to show off your new skills to your friends and family! What are the ...

    tips_python_

    python练习数据。机器人理财是将人工智能导入传统的理财顾问服务,并非由实体的机器人帮助客户理财,而是透过网络线上互动,依据需求者设定的投资目的及风险承受度,透过计算机程序的算法,提供自动化的投资组合建议...

    Beginning Python Games Development(Apress,2ed,2015)

    Learn how to create compelling ... You can also capitalize upon numerous tips and tricks the authors have accumulated over their careers creating games for some of the world's largest game developers.

    Python Graphics

    Starting with the essential Python functions to set up a plotting space and produce 2 and 3-dimensional objects, you’ll learn how to construct more complex objects, translate and rotate them, remove ...

    Beginning Python Games Development(2nd).pdf 2015第2版

    Paperback: 308 pages ... You can also capitalize upon numerous tips and tricks the authors have accumulated over their careers creating games for some of the world's largest game developers.

    自动办公实用tips Python自动发送邮件

    使用Python实现自动化邮件发送,可以让你摆脱繁琐的重复性业务,可以节省非常多的时间。我们把报表做出来以后一般都是需要发给别人查看,对于一些每天需要发的报表或者是需要一次发送多份的报表,这个时候可以考虑...

    小费数据集

    利用Python进行数据分析,小费数据集。

    Data Wrangling with Python

    Data Wrangling with Python 全面掌握用Python进行爬虫抓取以及数据清洗与分析的方法 轻松实现高效数据处理 https://item.jd.com/12219342.html

    KBEngine-Python-Tips-master.zip

    这个项目是为了给KBEngine服务端编写Python脚本的时候,让IDE有语法提示。

    Modern.Python.Cookbook.epub

    Chapter 2. Statements and Syntax Chapter 3. Function Definitions Chapter 4. Built-in Data Structures – list, set, dict Chapter 5. User Inputs and Outputs Chapter 6. Basics of Classes and Objects ...

Global site tag (gtag.js) - Google Analytics