![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
那年夏天KEEP
唯一幸运的就是喜欢这个行业
展开
-
python_6(dict_字典)
#dict(字典)-----------------dictionary_create.py---------------#!/usr/bin/python# -*- coding: UTF-8 -*-#使用字母作为索引dict = {"a" : "apple", "b" : "banana", "g" : "grape", "o" : "orange"}print dictprint原创 2015-10-17 22:38:11 · 286 阅读 · 0 评论 -
python_12(查找字符串、字符串查找、时间转换、正则、限定符、分组)
——————–查找字符串———————–#!/usr/bin/python# -*- coding: UTF-8 -*-# 查找字符串sentence = "This is a apple."print sentence.find("a")sentence = "This is a apple."print sentence.rfind("a")#输出>>> 810>>> ————原创 2015-10-18 00:46:00 · 379 阅读 · 0 评论 -
python_11(format、转义字符、连接字符、字符串操作函数、字符串反转)
——————–数据格式化—————————-#!/usr/bin/python# -*- coding: UTF-8 -*-# 格式化字符串str1 = "version"num = 1.0format = "%s" % str1print formatformat = "%s %d" % (str1, num)print format# 带精度的格式化print "浮点型数字: %原创 2015-10-18 00:35:37 · 1836 阅读 · 0 评论 -
python_8(自定义模型使用、内置函数)
---------------------自定义模型1----------------#--------myModule.py-----------#!/usr/bin/python# -*- coding: UTF-8 -*-# 自定义模块def func(): print "MyModule.func()"class MyClass: def myFunc(self):原创 2015-10-17 23:22:25 · 789 阅读 · 0 评论 -
python_10(内置模块)
内建函数和异常模块:__builtin__:定义内置函数include:len,int,range,apply,dir,type,callable,isinstance,issubclass,eval,compile,open,raw_input,print,__import__,reload,vers,execfileexceptions:定义所有内建异常include:Exception,I原创 2015-10-17 23:59:30 · 328 阅读 · 0 评论 -
python_4(tuple_元组)
#元组(tuple)-------------------tuple_create.py----------------------#!/usr/bin/python# -*- coding: UTF-8 -*-tuple = ("apple", "banana", "grape", "orange")#tuple[0] = "a"t = ("apple",)t = ()print t原创 2015-10-17 22:26:38 · 1149 阅读 · 0 评论 -
python_2(编译,变量、引号、变量类型、算数表达式)
一、用于编译pc文件为pyc文件 import py_compile py_compile.compile(‘hello.py’)#import py_compile #py_compile.compile('hello.py') 是用来编译py为pyc文件python下编译py成pyc和pyo其实很简单,用python -m py_compile file.pypython -m原创 2015-10-17 22:08:50 · 342 阅读 · 0 评论 -
python_1(对象,变量名,函数,分隔符,换行)
_rule = "rule information"#面向对象中的命名规则class Student: # 类名大写 __name = "" # 私有实例变量前必须有两个下划线 def __init__(self, name): self.__name = name原创 2015-10-17 21:31:41 · 1305 阅读 · 0 评论 -
python_3(循环语句、if、switch、for、break、冒泡算法)
----------------if循环-------------------# 执行if语句内的程序a = input("a:")b = input("b:")if(a > b): print a, " > ", b# 跳过if语句a = input("a:")b = input("b:")if(a > b): print a, " > ", bprint a, "原创 2015-10-17 22:20:28 · 1254 阅读 · 0 评论 -
python_5(list_列表)
#list(列表)----------------list_create.py----------------------#!/usr/bin/python# -*- coding: UTF-8 -*-list = ["apple", "banana", "grape", "orange"]print listprint list[2]list.append("watermelon")原创 2015-10-17 22:32:32 · 261 阅读 · 0 评论 -
python_7(索引、切片)
#!/usr/bin/python# -*- coding: UTF-8 -*-#索引操作tuple = ("apple", "banana", "grape", "orange")list = ["apple", "banana", "grape", "orange"]str = "apple"print tuple[0]print tuple[-1]print list[0]pr原创 2015-10-17 22:41:27 · 355 阅读 · 0 评论 -
python_9(获取字典值、函数参数、函数返回值、lambda的函数用法)
如果我们需要获取字典值的话,我们有两种方法,一个是通过dict[‘key’],另外一个就是dict.get()方法#获取字典值info = {'1':'first','2':'second','3':'third'}number = raw_input('input type you number:')print info.get(number,'error')#实例1#!/usr/bin/原创 2015-10-17 23:50:02 · 3433 阅读 · 0 评论