L[-1]相当于倒数第1个数
倒序切片包含起始索引,不包含结束索引。(L[-4:-1]提取出来不包括L[-1])
x:y相当于从x提取到y y不写时默认最后一位
x:y:z相当于从x到y以z为单位提取
倒序切片包含起始索引,不包含结束索引。(L[-4:-1]提取出来不包括L[-1])
x:y相当于从x提取到y y不写时默认最后一位
x:y:z相当于从x到y以z为单位提取
print [int(a+b+a) for a in '123456789' for b in '0123456789']
2018-07-20
def firstCharUpper(s):
return s[0:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
def firstCharUpper(s):
return s.title()
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
def firstCharUpper(s):
return s.title()
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2018-07-20
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2)
L.pop(2)
print L
L.pop(2)
L.pop(2)
print L
2018-07-20
L = ['Adam', 'Lisa', 'Bart']
L.insert(2, 'Paul')
print L
L.insert(2, 'Paul')
print L
2018-07-20
# -*- coding: utf-8 -*-
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
每个字符都很重要,python 输出提示检查 床前明月光是否输出,需要仔细确认句号和点的区别。
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
每个字符都很重要,python 输出提示检查 床前明月光是否输出,需要仔细确认句号和点的区别。
2018-07-20
for x in range(1,10): #range函数包括前面的,但不包括后面的,即1~9
for y in range(0,10):
if y > x:
print (x * 10 + y)
for y in range(0,10):
if y > x:
print (x * 10 + y)
2018-07-19
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum += x
print (sum)
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
sum += x
print (sum)
2018-07-19
自己打一定要记得在if判断加冒号!!!!
sum = 0
x = 1
n = 1
while True:
sum += x
x *= 2
n += 1
if n > 20:
break
print sum
sum = 0
x = 1
n = 1
while True:
sum += x
x *= 2
n += 1
if n > 20:
break
print sum
2018-07-19
sum = 0
x = 1
while x<100:
if x%2 != 0:
sum+=x
x+=1
print (sum)
x = 1
while x<100:
if x%2 != 0:
sum+=x
x+=1
print (sum)
2018-07-19
在主流的ide,如pycharm中tab等于4个空格,不过还是习惯大括号啊啊啊,不过可能很多人用大括号习惯不好,不注重缩减,影响观看,这方面可能python就好点,强迫你去缩进
2018-07-19
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2018-07-19