一.简介python
1.在python中数据以对象的形式出现。从更具体的角度来讲python能够分解成模块、语句、表达式以及对象。git
2.四者之间的关系以下:(1)程序由模块构成(2)模块包含语句(3)语句包含表达式(4)表达式创建并处理对象。编程
3.python的核心数据类型:数字、字符串、列表、元组、字典、文件、集合、其它类型(bool、None)、编程单元类型(函数、模块、类)。api
二python核心数据类型ssh
1.数字函数
数字类型种类:ui
python中的数字类型支持通常的数学运算spa
示例代码code
查看字符串长度:使用 len() 函数orm
2.字符串
序列的操做
内置的len()检验字符串的长度
示例代码
>>> a='uisduosduo'
>>> len(a)
10
>>> 'pppsippa'
'pppsippa'
>>> len('pppsippa')
8
字符串的索引格式为a[开始:结束]
>>> a[2]
's'
字符串的切片
>>> a[:]
'uisduosduo'
>>> a[:-1]
'uisduosdu'
>>> a[:-4]
'uisduo'
>>> a[-4:-1]
'sdu'
>>>
字符串的切片开始部分都不会取。
字符串能够进行加号运算
示例代码
>>> a='python'
>>> c=a+'hello'
>>> print(c)
pythonhello
>>> a='python'
>>> a+'xyt'
'pythonxyt'
>>> print(a)
python
>>>
虽然字符串a增长了字符,可是原始的a并无增长元素。
特定的类型方法
占位符的使用
%s和{}的使用
示例代码
>>> '%s,egg,%s'%('hello','world!')
'hello,egg,world!'
>>> '{0},egg,{1}'.format('hello','world')
'hello,egg,world'
>>>
3.寻求帮助
使用函数dir(对象);返回的参数受对象的影响,但返回的都是一个列表,该列表包含函数属性和一些该对象自带的函数。
示例代码
>>> dir('split')
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
help()函数
Help on built-in function replace:
replace(...) S.replace(old, new[, count]) -> string Return a copy of string S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced.