python初级操作:类,函数
来源:互联网 发布:php常用算法 编辑:程序博客网 时间:2024/06/11 00:22
1,创建类和函数:
#coding=utf-8
class STUDENT:
def __init__(self,name):
self.name=name
def sayhell0(self):
print "hello,"+self.name
class my:
def __init__(self,age):
self.age=age
def sayage(self):
print "my age is "+self.age
nam=STUDENT("小明")
nam.sayhell0()
x=my("13")
x.sayage()
#encoding=UTF-8
def PRINT():
return "你好"
def max(a,b):
if a>b:
print str(a)+">"+str(b)
else:
print str(a)+"<"+str(b)
print PRINT()
a=max(1,2)
b=max(3,1)
STRING="我在这儿呢A"
A=len(STRING)
print A #中文每个字符占3个字节,英文占1个
自定义函数:
1,创建函数
2保存为.PY文件
3,放入python安装目录中的lib目录下
4,调用 from py文件名 import 函数名
re模块
调用re模块需要用到正则表达式
sub:替换模块
findall:查找字符串,遍历全部
search:从左向右遍历,匹配一次就结束,不会再遍历后面。
阅读全文
0 0
- python初级操作:类,函数
- Python的灵活性--初级函数
- 初级操作
- python-初级
- python初级
- python+selenium初级(2)—简单元素的操作
- Python内置函数_集合操作类
- Python内置函数_IO操作类
- Python内置函数_集合操作类
- python 字符串操作函数
- python 目录操作函数
- Python 文件操作函数
- python 字符串操作函数
- Python学习笔记-初级(二):模块与函数
- PYTHON文件操作常用函数
- Python中字符串操作函数
- python字符串函数操作大全
- [python]join函数操作字符串
- springmvc+mybatis实现简单的图书管理系统
- css阻塞与js阻塞
- kilim
- 1104. Sum of Number Segments (20)
- hdu2083 简易版之最短距离(C语言)
- python初级操作:类,函数
- strcpy等函数的模拟实现
- Spring通过dataSource获取数据库的连接测试
- 《Angular路由跳转之指令跳转》
- NSArray实战
- C++实现TCP通信
- 开源库MOGRE托管版编译教程
- ViewPager初识
- 关于附件上传