boss=['john','lisa','bob','jack','takashi','nori','mari','sachi']
n=1
for n in range(5):
print(boss[n])
john
lisa
bob
jack
takashi
def show_member(n):
even=[]
odd=[]
for member in range(len(boss)):
if(member%2==0):
even.append(boss[member])
else:
odd.append(boss[member])
if(n==1):
print(even)
if(n==2):
print(odd)
show_member(1)
show_member(2)
['john', 'bob', 'takashi', 'mari']
['lisa', 'jack', 'nori', 'sachi']
def print_msg(word):
print('--------------------')
print(word)
print('--------------------')
def show_member(num,mlist):
even=[]
odd=[]
for n in range(len(mlist)):
if(n%2==0):
odd.append(mlist[n])
else:
even.append(mlist[n])
if(num%2==0):
show_list(odd)
else:
show_list(even)
def show_list(mlist):
for member in mlist:
print(member)
boss=['john','lisa','bob','jack','takashi','nori','mari','sachi']
print_msg('start')
show_member(7,boss)
print_msg('end')
--------------------
start
--------------------
lisa
lisa
jack
lisa
jack
nori
lisa
jack
nori
sachi
--------------------
end
--------------------
def getLen():
boss=['john','lisa','bob','jack','takashi','nori','mari','sachi']
#print(len(boss))
return len(boss)
#返り値
#戻り値
#getLen()
print(getLen())
8
def getLenList(mlist):
return (mlist)
boss=['john','lisa','bob','jack','takashi','nori','mari','sachi']
team=['john','lisa','bob']
return (mlist)
print('len',getLenList(team))
print('len',getLenList(boss))
cnt=getLenList(boss)
for n in range(len(cnt)):
print(boss[n])
john
lisa
bob
jack
takashi
nori
mari
sachi
class showList:
def show_list(self,mlist): #self
for member in mlist:
print(member)
def getLenList(self,mlist): #self
return len(mlist)
def say(self):
print('hello')
boss=['john','lisa','bob','jack','takashi','nori','mari','sachi']
s=showList()
s.show_list(boss)
s.say()
john
lisa
bob
jack
takashi
nori
mari
sachi
hello
class hero:
def say(self,name):
print('my name is sato')
h=hero()
h.say('sato')
my name is sato
team=['sato','nao','john','lisa','kaoru','ryo','bob','jack','mary','linda','yosuke','takashi','saori', 'yuki','tomo', 'take','yusuke','nori','mari','sachi']
boss=['john','lisa','bob','jack','takashi','nori','mari','sachi']
staff=[]
for member in team:
if(member in boss):
staff.append(member + ' leader')
def show_list(mlist):
for member in mlist:
print(member)
show_list(staff)
john leader
lisa leader
bob leader
jack leader
takashi leader
nori leader
mari leader
sachi leader
from pprint import pprint
score = {}
score['jp'] = 79
score['math'] = 85
score['rika'] = 88
score['shaka'] = 70
pprint(score)
{'jp': 79, 'math': 85, 'rika': 88, 'shaka': 70}
keys=score.keys() #keyだけをリストに
print(keys)
for key in keys:
print(score[key])
score = {}
score['jp'] = 88
score['math'] = 91
score['rika'] = 72
score['shakai'] = 81
print(score)
sum = 0
keys=score.keys()
for key in keys:
print(score[key])
sum = sum + score[key]
print(sum)
print(sum/len(keys))
-----
dict_keys(['jp', 'math', 'rika', 'shaka'])
79
85
88
70
{'jp': 88, 'math': 91, 'rika': 72, 'shakai': 81}
88
91
72
81
332
83.0
useradd ken ; mkdir -p /home/ken/tmp/ ; cd /home/ken/tmp/ ;
tail -1 /etc/passwd > ken.txt ; id >> ken.txt ; date >> ken.txt ; cal 2018 > ken.txt ; tail -10 /var/log/dmesg > dmesg1.txt ;
head -20 /var/log/dmesg >> dmesg1.txt ; chmod 444 *.txt ;
create view bobo (name, age, address, flag1)
as
select name,age,address,
case
when (age between 10 and 19) and address in('tokyo','kyoto') then 1
when (age between 20 and 29) and address in('tokyo','kyoto') then 2
when (age between 30 and 39) and address in('tokyo') then 3
when (age between 40 and 49) and address in('tokyo','kyoto') then 4
else
end as flag
from userlist ;