s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
print s
2018-10-13
#input code
print 'Hello,python'
print 'hello','python'
print 'hello'',''python'
print 'hello,''python'
print 'hello'',python'
a = 'Hello,python'
print a
print 'Hello,python'
print 'hello','python'
print 'hello'',''python'
print 'hello,''python'
print 'hello'',python'
a = 'Hello,python'
print a
2018-10-13
第一节练习答案:
print 45678 + 0x12fd2
print 'Learn Python in imooc'
print 100 < 99
print 0xff == 255
print 45678 + 0x12fd2
print 'Learn Python in imooc'
print 100 < 99
print 0xff == 255
2018-10-13
建议所有看不懂的同学,看下这个帖子
https://blog.csdn.net/not_guy/article/details/72823951
如果能理解这里面的每一步,应该就可以理解这个逻辑了
https://blog.csdn.net/not_guy/article/details/72823951
如果能理解这里面的每一步,应该就可以理解这个逻辑了
2018-10-12
参考答案给的是小写字母,而且数值还不一样,所以这样就OK了
L = ['adam',95.5,'lisa',85,'bart',59]
print L
L = ['adam',95.5,'lisa',85,'bart',59]
print L
2018-10-11
sum = 0
x = 1
n = 1
while True:
sum+=x
n=n+1
x=pow(2,n-1)
if n>20:
break
print sum
x = 1
n = 1
while True:
sum+=x
n=n+1
x=pow(2,n-1)
if n>20:
break
print sum
2018-10-11
d = {
'Adam':95,
'Lisa':85,
'Bart':59,
}
d['Paul']=75
e=sorted(d)
print e
'Adam':95,
'Lisa':85,
'Bart':59,
}
d['Paul']=75
e=sorted(d)
print e
2018-10-11
for x in [1,2,3,4,5,6,7,8,9]:
for y in [1,2,3,4,5,6,7,8,9]:
if y<=x:
continue
print x*10+y
for y in [1,2,3,4,5,6,7,8,9]:
if y<=x:
continue
print x*10+y
2018-10-10
import math
def quadratic_equation(a, b, c):
x=(math.sqrt(b*b-4*a*c)-b)/(2*a)
y=(-math.sqrt(b*b-4*a*c)-b)/(2*a)
return x,y
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
x=(math.sqrt(b*b-4*a*c)-b)/(2*a)
y=(-math.sqrt(b*b-4*a*c)-b)/(2*a)
return x,y
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-10-10
print [int(x + y + z) for x in '123456789' for y in '0123456789' for z in '123456789' if x == z ]
2018-10-10
当执行L.pop(2)之后,L中存放的字符串只剩3个,Bart的索引位变为2。对于删除Bart的命令,可以再次执行L.pop(2)或者执行L.pop(-1),反正最后一位总是Bart,就不用考虑变位了。
2018-10-09
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name
for index, name in enumerate(L):
print index+1, '-', name
Python自然调用ascii编码解码程序去处理字符流,当字符流不属于ascii范围内,就会抛出异常。所以解决方法就是修改默认编码,需要注意的是需要先调用reload方法。
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
print u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
这样就可以了。但现在编辑器支持中文了,所以不用加u也可以的
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
print u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
这样就可以了。但现在编辑器支持中文了,所以不用加u也可以的
2018-10-09