截取最后三位:
aa=“TFR20171230001-1”
cc=aa[-3]+aa[-2]+aa[-1]
aa="1.36x36.8-ddr"
bb=aa.split('x')[1] :值36.8-ddr
ss=bb.split('-')[0] :值1.36
截取时间:aa=2017-12-30 21:57 :00:00
截取日期:bb=aa[0:10]
print bb是2017-12-30
在Python中,实例的变量名如果以__
开头,就变成了一个私有变量(private),
只有内部可以访问,外部不能访问:
class Student(object):
def __init__(self, name, score):
self.__name = name
self.__score = score
def print_score(self):
print('%s: %s' % (self.__name, self.__score))
在Python中,实例的变量名如果以__
开头,就变成了一个私有变量(private)
,只有内部可以访问,外部不能访问,所以,我们把Student类改一改:
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
clsaa Student(object):
def __init__(self,name,score):
self.__name=name
self.__score=score
def get_name(self):
return self.__name
def get_score(self):
return self.__score
def set_score(self,score):
if 0<=score<=100:
self.__score=score
else:
raise ValueError('bad score')
def get_grade(self):
if self.__score>=90:
return 'A'
elif self.__score>=60:
return 'B'
else:
return 'C'
bart=Student('tomcat',59)
print ('bart.get_name()=',bart.get_name())
bart.set_score(60)
print ('bart.get_score()=',bart.get_score())
print ('DO NOT use_bart._Student_name:',bart._Student_name)