码迷,mamicode.com
首页 > 编程语言 > 详细

python帮助

时间:2017-10-24 22:30:37      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:python   help   类型转换   

查看函数使用方法

help(raw_input)

帮助中的[]为可选的内容


查看数据类型有哪些方法

a1={ ‘a‘:1,‘b‘:2,‘c‘:3 }

print (dir(a1))

输出:[‘__class__‘, ‘__contains__‘, ‘__delattr__‘, ‘__delitem__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘...]


查看元素是哪个类型的

a1={ ‘a‘:1,‘b‘:2,‘c‘:3 }

print (type(a1))

输出:<class ‘dict‘>


python变量类型转换

int()    转换为整数

hex()    将10进制转化为2进制

str()    转化为字符串

列表与字典相互转换

字符串转列表

list(string)

列表转字符串

‘.‘.join(a)用.来做分隔符转换到字符串

字符串转元组

tuple(string)

元组转字符串

‘‘.join(tuple)

字典转换为列表,列表里的元素是元组,元组存的值为字典的key和value

dic.items()

反转回字典使用dict(l1)


本文出自 “粗粮面包” 博客,请务必保留此出处http://culiangmianbao.blog.51cto.com/10475024/1975747

python帮助

标签:python   help   类型转换   

原文地址:http://culiangmianbao.blog.51cto.com/10475024/1975747

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!