1、格式化
>>> from math import pi >>> '%10f' % pi ' 3.141593' >>> '%10f' % pi # 字段宽10 ' 3.141593' >>> '%10.2f' % pi #字段宽10,精度2 ' 3.14' >>> '%.5s' % 'Hello world' 'Hello' >>> '%010.2f' % pi #宽度为10,其余位用0填充 '0000003.14'
2、字符串方法
>>> subject = '$$$ Get rich now!!! $$$' >>> subject.find('$$$') 0 >>> subject.find('$$$',1) 20 >>> subject.find('!!!') 16 >>> subject.find('!!!',0,16) -1 >>> # join 是split的逆操作 >>> seq = [1,2,3,4] >>> sep = '+' >>> sep.join(seq) Traceback (most recent call last): File "<pyshell#67>", line 1, in <module> sep.join(seq) TypeError: sequence item 0: expected string, int found >>> seq = ['1','2','3','4'] >>> sep.join(seq) '1+2+3+4' # strip 返回去除两侧空格的字符串 >>> ' hello world '.strip() 'hello world' >>> # translate 不同于replace处为只处理单个字符,但可以批量 >>> from string import maketrans >>> table = maketrans('cs','kz') >>> 'this is an incredible test'.translate(table) 'thiz iz an inkredible tezt'
相关推荐
本部分介绍了Python语言的基础知识,包括基本编程概念、字符串处理、数字和操作符、变量的使用等。这些章节为读者提供了Python语言的入门知识,帮助读者快速上手Python语言。 ### Chapter 1: Programming Basics ...
《 Beginning Python:Using Python 2.6 and Python 3.1》是一本旨在引导初学者入门Python编程语言的书籍,特别关注Python 2.6和3.1这两个版本。这本书涵盖了从基本语法到高级概念的广泛主题,为读者提供了一个全面...
Updated to reflect the latest in Python programming paradigms and several of the most crucial features found in Python 3, Beginning Python also covers advanced topics such as extending Python and ...
Beginning python 3.pdf
Chapter 13: Writing a GUI with Python 209 GUI Programming Toolkits for Python 209 PyGTK Introduction 210 pyGTK Resources 211 Creating GUI Widgets with pyGTK 213 Try It Out: Writing a Simple pyGTK...
Beginning Python from Novice to Professional Beginning Python from Novice to Professional
在本压缩包中,"beginning-python-3ed-source-code"目录下的"beginning-python-3ed-master"包含了书中所有示例程序的源代码,这为我们提供了探索和实践Python编程的绝佳平台。 Python是一种高级、解释型、交互式和...
Beginning Python Games Development, 2nd Edition will teach you how to create visuals, do event handling, create 3D games, add media elements, and integrate OpenGL into your Python game. In this ...
Beginning Python Games Development, Second Edition
Chapter 1: Programming Basics and Strings 3 Chapter 2: Numbers and Operators 15 Chapter 3: Variables — Names for Values 31 Part II: Python Language and the Standard Library 49 Chapter 4: Making ...
1. **Python语法基础**:包括变量定义、数据类型(如整型、浮点型、字符串、布尔型、列表、元组、字典和集合)、运算符(算术、比较、逻辑)、流程控制(if语句、for循环、while循环)、函数定义和调用等。...
Beginning Python From Novice to Professional(3rd) 英文epub 第3版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Python基础教程 Beginning Python From Novice to Professional.zip,收录了 Python基础教程 Beginning Python From Novice to Professional 中英文各版本和源码,包括(第2版)和 (第3版),都有详尽的书签,不是一级...
- 变量与数据类型:Python支持整型、浮点型、字符串、布尔型等多种数据类型,以及列表、元组、字典和集合等复合数据结构。 - 控制流:包括条件语句(if-else)、循环语句(for、while)以及异常处理(try-except)...
- 变量与数据类型:Python 3支持多种数据类型,如整型(int)、浮点型(float)、字符串(str)和布尔型(bool)。此外,还有列表(list)、元组(tuple)、字典(dict)和集合(set)等复合类型。 - 控制流程:...
“开始Python:使用Python 2.6和Python 3.1引入了这种开源的、可移植的、解释的、面向对象的编程语言,它结合了强大的功能和清晰的语法。本书通过讲授基础知识,使您能够快速创建健壮、可靠和可重用的Python应用程序...
在Python语法方面,本书详细介绍了Python的基础语法元素,包括变量、数据类型(如整型、浮点型、字符串、列表、元组、字典等)、控制结构(如if语句、for循环、while循环)、函数定义与调用、类与对象等面向对象编程...
Beginning Python Visualization(2nd) 英文无水印pdf 第2版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权...
Beginning Python From Novice to Professional(3rd) 英文无水印pdf 第3版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自...
Beginning Python From Novice to Professional 3rd Edition by Magnus Lie Hetland