Python基础
对于Python,一切事物都是对象,对象基于类创建
不同类型的类可以创造出字符串,数字,列表这样的对象,比如"koka"、24、['北京', '上海', '深圳']
数据类型
1、如何查找数据类型支持的方法
python终端:
name=”koka“ type(name) <class 'str'> help(str) #即可显示所有字符串支持的方法
或者
dir(name) #也可以显示对象中的所有特性。
使用Pycharm:
在py文件中输入int或str,选中输入的关键字,按住Ctrl等鼠标变成手指标识,左键单击即可到你想查找的类方法介绍
选中int后按如下操作可以在pycharm的左侧显示int(object)的方法,方便查看
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeoAAAJVCAIAAACeeyFQAAAgAElEQVR4nO3d6XMUd57n8fpvtu3weB7ogakHs9HR6+lu93TsdHvchxUbPY4NXO2xt8PFuWOwW5wGcZS5bSMuCwxtY3GrOM0hYW7EYQOixGUkwPZgDiPRZiWofZB1ZGZlZmVWVf7y+yu9Fa/oqMqqzPwVuD+kflmZn1hLS8vU5oUAAL3EWlparvbd6b35Paq0Zt3Gq313AECNWEtLy7EvezuOZ1CNcz03F7WsPfZlLwCokYvvA8cuohpfZW4Q3wBUysX3/qPdqMZXmRsLlxLfQB06eCJz4lxf5MMolY/vIxdQjS8v9i388OPI/zoB1NznnV2nu29GPoxSsZaWlqNnr+89dL6slxbv8uZnI/XqbPf1+R+sPnr2OoCQHD59rXXd5qnTm8eOGz923Pip05tb120+fPpaBZtKJpP+37xtx/6ver7xudlAW65SLr4/P3SurAVbjhkmrD3oGN9+NlKviG8gVPuPnJ889d1kMjl1erORksaDyVPf3X/kfNCtBQrZ9Ru2dF/9zu3VvYe+mj13wYFj3QdPXDIGdvDEpQPHumfPXbD30FcVfNJk/qfsO2MtLS1Hzny9++CXbiaU/Di+7aXFuzw24t+udeOejv3ja+vO1mRrypw5//W8JR8dOfM1gJo7dOrq5CnTx40bv6F9/5EzXxvpduTM1xva948bN37SlGmHuq743NSiD1YW8nHRByv9rLJ6zdqer2+7vTp77oJkMjnx7XfGjhtvbHbsuPET334nmUzOmrugg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r7FoaoYgB/EtywhVBXXiNeV31Wi5hioBPEtSDhVxTUSJL6pOVaAC+5BfAsSTlVxjfiPb2qOFeF2V8Md8S1IOFXFNeI7vqk5VvqXIvAOi1CF+BYktKrihlQ6dwelfKmj7VZK5nsQmicKrPcm9BXf1BxTcwxFiG9BQqsqzueCEdz2ZgPrHU2L9bu2Vh2f8U3NMTXHUIT4FiS0qmJzrWLJY6cmxlwkeRU2uqDmmJpjqEJ8CxJaVXHQ+HZa7nfum5pjao6hCPEtSGhVxZ7xXTp5Yjrcc/gt3v/uqDmm5hhhIr5lCaeq2Du++1xPXRbnOizn0LxRc0zNMdQgvsURUVVcDWqO1QyYie9hj/iWKOSq4mpQcxw2ao7hF/GNeqdda7B2A0ZEiG8A0BLxDQBaIr4BQEvENwBoifgGAC0R3wCgJeJbIqqKAZRFfItDVTEAP4hvWcRUFYd3KzuKiYHacIvv/w9g3xneYbA0gAAAAABJRU5ErkJggg==" alt="" />
整数
加法:x.__add__(y) <==> x+y
>>> x=
>>> y=
>>> x.__add__(y) >>> x+y
abs : 求绝对值,x.__abs__() <==> abs(x)
>>> x=-
>>> abs(x) >>> x.__abs__()
divmod:相除,得到商和余数组成的元组 x.__divmod__(y) <==> divmod(x, y) #在网页分页操作中使用。
>>> total =
>>> pager =
>>> total.__divmod__(pager)
(, )
>>> divmod(total,pager)
(9, 5)
字符串
>>> name = "koka"
>>> print("hello %s" %name)
hello koka
>>> '%10f' % pi #字符宽度 10
' 3.141593'
>>> '%10.2f' % pi #字符宽度10,精度2
' 3.14'
>>> '%.2f' % pi #精度2
'3.14'
>>> '%.*s' %(5,'Guido van Rossum')
'Guido'
>>> '%010.2f' % pi
'0000003.14'
>>> '%-10.2f' % pi
'3.14
>>> 'With a moo-moo here'.find('moo')
>>> seq = [1,2,3,4,5]
>>> sep = '+'
>>> sep.join(seq)
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
sep.join(seq)
TypeError: sequence item 0: expected str instance, int found >>> seq = ['1','2','3']
>>> sep = '+'
>>> sep.join(seq)
'1+2+3'
print('Hello'.lower())
name = 'lolo lala lola'
print(name.replace('lolo','koka'))
>>> '1+2+3'.split("+")
['1', '2', '3']
>>> ' hahaha '.strip()
'hahaha'
capitalize 首字母变大写
>>> name = "python"
>>> name.capitalize()
'Python'
in or __contain__ 包含
>>> name = "python"
>>> name.capitalize()
'Python'
>>> name.__contains__('th')
True
startswith 和 endswith 以xx开头或xx结尾
>>> name = "Gumby"
>>> name.endswith('Gumby')
True
>>> name = "Mr.Gumby"
>>> name.startswith('Mr.')
True
ljust,center,rjust 左对齐,居中,右对齐
>>> print(''.ljust(35,'='))
===================================
>>> print("Shopping List:".center(35,"*"))
***********Shopping List:**********
>>> print(''.rjust(35,'='))
===================================
count 统计字符出现次数
>>> abc = 'asdadqweqjkhwjgfawgdklawda'
>>> abc.count('a') >>> abc.count('a',,)
encode 编码
>>> name = "下载"
>>> result = name.encode('gbk')
>>> print(result)
b'\xcf\xc2\xd4\xd8'
format 格式化字符串
>>> s = "i am {0},age {1}"
>>> print(s.format('Tang',18))
i am Tang,age 18 >>> s = 'i am {name},age {age}'
>>> print(s.format(name="Tang",age=18))
i am Tang,age 18
更多字符串format的使用参考:http://blog.csdn.net/handsomekang/article/details/9183303
列表
>>> [0,1,2,3,4,5]
[0, 1, 2, 3, 4, 5]
>>> ['th'] * 10
['th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th'] >>> 0 in [0,1,2,3,4,5]
True >>> num = [0,1,2,3,4,5]
>>> num[:]
[0, 1, 2, 3, 4, 5]
>>> num[0:3]
[0, 1, 2]
>>> lst = [1,2,3]
>>> lst.append(4)
>>> lst
[1, 2, 3, 4]
>>> a = [1,2,3]
>>> b = [4,5,6]
>>> a.extend(b)
>>> a
[1, 2, 3, 4, 5, 6]
>>> a.pop()
>>> ['a','b','c','a'].count('a')
products = ['Car','Iphone','Coffee','Mac','clothers','Bicyle']
print(products.index('Mac'))
prices = [,,,,,]
prices.insert(,)
print(prices)
[, , , , , , ]
>>> li = [11,22,33,44,55]
>>> li.remove(11)
>>> li
[22, 33, 44, 55]
>>> x = [1,3,5,2,6,8]
>>> x.sort()
>>> x
[1, 2, 3, 5, 6, 8]
>>> x.reverse()
>>> x
[8, 6, 5, 3, 2, 1]
print(list(reversed([,,,,])))
[, , , , ]
>>> y = sorted(x)
>>> y
[1, 2, 3, 5, 6, 8]
' '.join(list)
元组
元组不可以改变,元组下的元素是可以改变的。
>>> tu.remove(11)
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
tu.remove(11)
AttributeError: 'tuple' object has no attribute 'remove'
>>>
>>> tu = (,[,],"haha",)
>>> tu[][]=
>>> tu
(, [, ], 'haha', )
count 统计出现次数
>>> tu = (,,,)
>>> tu.count()
index 查找元素出现的位置
>>> tu.index() >>> tu.index()
字典
{'key':'value'}
copy 返回一个具有相同键值对的新字典(这个方法实现的是浅复制,因为值本身就是相同,而不是副本。)
>>> x ={'username':'koka','sx':['it','js',12345]}
>>> y = x.copy()
>>> y['username'] = 'akok'
>>> y['sx'].remove('it')
>>> y
{'username': 'akok', 'sx': ['js', 12345]}
>>> x
{'username': 'koka', 'sx': ['js', 12345]}
{}.fromkeys(['name','age'])
{'age':'None','name':'None'} dict.fromkeys(['name','age'])
{'age':None,'name':None}
get 访问字典项的方法,一般来说访问字典中不存在的项时会出错。
d={}
print(d['name'])
error
print(d.get('name'))
None
data = {'name':'koka','age':}
if 'name' in data:
print("in")
else:
print("not in")
in
items 和 iteritems
>>> database={'koka':'123','wawa':'456'}
>>> for key,value in database.items():
print(key,value)
wawa 456
koka
data = {'name':'koka','age':}
name = data.pop('name')
print(name)
koka
popitem 类似与list.pop,后者会弹出列表的最后一个元素。popitem弹出随机的项,可一个接一个的移除项。
setdefault类似于get,能够获得与给定键相关联的值,还能在字典中不含有给定键的情况下设定值。
>>> d = {}
>>> d.setdefault('name','N/A')
'N/A'
data = {'name':'koka','age':}
adds = {'phone':}
data.update(adds)
print(data)
{'phone': , 'name': 'koka', 'age': }
>>> dct = {'a':1,'b':2}
>>> print(type(dct.keys()))
<class 'dict_keys'>
>>> d={}
>>> d[1]=1
>>> d[2]=2
>>> d[1]=1
>>> d.values()
dict_values([1, 2])
>>> print(type(d.values()))
<class 'dict_values'
>>> phonebook={'tr':'1234'}
>>> print("tr's phone number is %(tr)s." %phonebook)
tr's phone number is 1234.
>>> items=[('name','koka'),('age',18)]
>>> d=dict(items)
>>> d['name']
'koka'
dict函数也可以通过关键字参数来创建字典
>>> d = dict(name='koka',age=18)
>>> d
{'name': 'koka', 'age': 18}
练习:元素分类
有如下值集合 [11,22,33,44,55,66,77,88,99,90...],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中。
即: {'k1': 大于66 , 'k2': 小于66}
a = [,,,,,,,,]
b = {}
for item in a:
if item >= :
if 'k1' in b:
b['k1'].append(item)
else:
b['k1'] = [item,]
else:
if 'k2' in b:
b['k2'].append(item)
else:
b['k2'] = [item,]
print(b)
"""
for i in a:
if i >=:
b.setdefault('k1',[]).append(i)
else:
b.setdefault('k2',[]).append(i)
print(b)
"""
"""
import collections
values = [11, 22, 33,44,55,66,77,88,99]
newvalues = collections.defaultdict(list) for i in values:
if i >= 66:
newvalues['k1'].append(i)
else:
newvalues['k2'].append(i)
print(newvalues)
"""
python学习笔记二 数据类型(基础篇)的更多相关文章
-
python学习笔记(二)、字符串操作
该一系列python学习笔记都是根据<Python基础教程(第3版)>内容所记录整理的 1.字符串基本操作 所有标准序列操作(索引.切片.乘法.成员资格检查.长度.最小值和最大值)都适用于 ...
-
Python学习笔记【第四篇】:基本数据类型
变量:处理数据的状态 变量名 = 状态值 类型 python中有以下基本数据类型: 1:整形 2:字符串类型 3:Bool类型 4:列表 5:元祖(不可变) 6:字典(无序) 7:集合 (无序.不重复 ...
-
Python 学习笔记二
笔记二 :print 以及基本文件操作 笔记一已取消置顶链接地址 http://www.cnblogs.com/dzzy/p/5140899.html 暑假只是快速过了一遍python ,现在起开始仔 ...
-
(10.1)Python学习笔记二
1.在项目工程中要模块化测试一个开发的功能,在测试通过后交付给项目组其他人员继续开发.要保证代码开发的性能和效率以及可扩展性. 2.项目工程中的文件夹分类要功能模块明确清晰,在python中引入某一个 ...
-
Python学习笔记 - day3 - 数据类型及运算符
Python的数据类型 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同 ...
-
(C/C++学习笔记) 二. 数据类型
二. 数据类型 ● 数据类型和sizeof关键字(也是一个操作符) ※ 在现代半导体存储器中, 例如在随机存取存储器或闪存中, 位(bit)的两个值可以由存储电容器的两个层级的电荷表示(In mode ...
-
python学习笔记(二):python数据类型
上一篇博客写了python的入门和简单流程控制,这次写python的数据类型和各种数据类型的内置方法.一.数据类型是什么鬼?计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各 ...
-
python学习笔记之数据类型(二)
上一篇博客,小波介绍了python的入门和简单流程控制,这次写python的数据类型和各种数据类型的内置方法. 一.数据类型是何方神圣? 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当 ...
-
02 Python学习笔记-基本数据类型(二)
一.基本知识 1.缩进: 2.一行多条语句: 3.断行: 4.注释 # 单行注释 '''这是一段 多行注释''' 5. 变量 1. 变量类型(局部变量.全局变量.系统变量) 2. 变量赋值 多重赋值x ...
随机推荐
-
python基础教程-第二章-列表和元组
本章将引入一个新的概念,:数据结构.数据结构是通过某种方式(例如对元素进行编号)组织在 一起的数据元素的集合,这些数据元素可以是数字或者字符,甚至可以是其他数据结构.在python中,最基本的数据结构 ...
-
python 之验证码
验证码原理在于后台自动创建一张带有随机内容的图片,然后将内容通过img标签输出到页面. 安装图像处理模块: pip3 install pillow
-
iOS学习笔记---c语言学习第七天
结构体 结构体是一种自定义的数据类型 struct 结构体名 { 类型说明符 成员名: … 类型说明符 成员名: }: #import <Foundation/Foundation.h& ...
-
时序列数据库武斗大会之 OpenTSDB 篇
[编者按] 刘斌,OneAPM后端研发工程师,拥有10多年编程经验,参与过大型金融.通信以及Android手机操作系的开发,熟悉Linux及后台开发技术.曾参与翻译过<第一本Docker书> ...
-
EM算法--第一篇
在统计计算中,最大期望(EM)算法是在概率(probabilistic)模型中寻找参数最大似然估计或者最大后验估计的算法,其中概率模型依赖于无法观测的隐藏变量(LatentVariable).最大期望 ...
-
catalan卡特兰数
卡塔兰数是组合数学中一个常在各种计数问题中出现的数列.以比利时的数学家欧仁·查理·卡塔兰(1814–1894)命名.历史上,清代数学家明安图(1692年-1763年)在其<割圜密率捷法>最 ...
-
【Thinkphp 5】 整合邮箱类 phpmailer实现邮件发送
第一步:下载phpmailer文件,主要用到的文件只有箭头指向的两个,thinkphp5中,把class.phpmailer.php改成了phpmailer.php 第二步: 将phpmailer文件 ...
-
sourceTree如何不用注册就使用
下载好之后会有这么一个界面要求你注册或登录.(不管它)将下面的一串串放进我的电脑的地址栏,打开sourcetree的文件夹 %LocalAppData%\Atlassian\SourceTree\ 注 ...
-
使用 Web 服务 为 ECS Linux 实例配置网站及绑定域名
Nginx 服务绑定域名 https://help.aliyun.com/knowledge_detail/41091.html?spm=a2c4e.11155515.0.0.4lvCpF 以 YUM ...
-
Lucene.net的简单使用
一.Lucene.net的简单介绍 1.为什么要使用Lucene.net 使用like的模糊查询,模糊度太低,中间添加几个字就无法查找.同时会造成数据库的全文检索,效率低下,数据库服务器造 ...