# -*- coding: UTF-8 -*-
S = ['Adam', 'Lisa', 'Bart']
#追加到末尾
S.append('paul')
print 'S=',S
#添加到任意位置
S.insert(0,'mary')
print '\nS=',S,'\n'
L = ['Adam', 'Lisa', 'Bart']
L.insert(2,'Paul')
print L
S = ['Adam', 'Lisa', 'Bart']
#追加到末尾
S.append('paul')
print 'S=',S
#添加到任意位置
S.insert(0,'mary')
print '\nS=',S,'\n'
L = ['Adam', 'Lisa', 'Bart']
L.insert(2,'Paul')
print L
2018-05-23
仔细看了一下报错,L.pop(3)出了问题,看了一下小伙伴的代码,想了想,想通了,原来第一次删除以后,L的值会变化,然后下一个会采用变化后的值去执行
2018-05-23
# -*- coding: UTF-8 -*-
L = [95.5, 85, 59]
print '倒数第一:',L[-1]
print '倒数第二:',L[-2]
print '倒数第三:',L[-3]
print '测试倒数第四:',L[-4]
'''Traceback (most recent call last):
File "index.py", line 6, in
print '测试倒数第四:',L[-4]
IndexError: list index out of range
'''
L = [95.5, 85, 59]
print '倒数第一:',L[-1]
print '倒数第二:',L[-2]
print '倒数第三:',L[-3]
print '测试倒数第四:',L[-4]
'''Traceback (most recent call last):
File "index.py", line 6, in
print '测试倒数第四:',L[-4]
IndexError: list index out of range
'''
2018-05-22
# -*- coding: UTF-8 -*-
L = [95.5,85,59]
print '第一名:',L[0]
print '第二名:',L[1]
print '第三名:',L[2]
print '测试L[3]:',L[3]
'''Traceback (most recent call last):
File "index.py", line 6, in
print '测试L[3]:',L[3]
IndexError: list index out of range
'''
L = [95.5,85,59]
print '第一名:',L[0]
print '第二名:',L[1]
print '第三名:',L[2]
print '测试L[3]:',L[3]
'''Traceback (most recent call last):
File "index.py", line 6, in
print '测试L[3]:',L[3]
IndexError: list index out of range
'''
2018-05-22
# -*- coding: UTF-8 -*-
'''列表 list 用 [ ]表示,是一种有序的集合,可以随时添加和
删除其中的元素'''
S=['michael',100,True] #可包含多种数据类型的数据
print 'S=',S
empty_list=[]
print '\n空list:',empty_list
L = ['adam', 95.5, 'lisa', 85, 'bart', 59]
print '\nL=',L
'''列表 list 用 [ ]表示,是一种有序的集合,可以随时添加和
删除其中的元素'''
S=['michael',100,True] #可包含多种数据类型的数据
print 'S=',S
empty_list=[]
print '\n空list:',empty_list
L = ['adam', 95.5, 'lisa', 85, 'bart', 59]
print '\nL=',L
2018-05-22
# -*- coding: UTF-8 -*-
s=True
print s and 's=T' or 's=F'
# a and b : 若a为真,返回b;若a为假,则返回a.
# a or b : 若a为真,返回a;若a为假,则返回b.
a = 'python'
print '\nhello,', a or 'world'
print '连接词为or,a为真,故返回a'
b = ''
print '\nhello,', b or 'world'
print '连接词为or,b为假,故返回\'world\''
s=True
print s and 's=T' or 's=F'
# a and b : 若a为真,返回b;若a为假,则返回a.
# a or b : 若a为真,返回a;若a为假,则返回b.
a = 'python'
print '\nhello,', a or 'world'
print '连接词为or,a为真,故返回a'
b = ''
print '\nhello,', b or 'world'
print '连接词为or,b为假,故返回\'world\''
2018-05-22
# -*- coding: UTF-8 -*-
print '整数除以整数的结果还是整数:'
print '2.5 + 10/4 =',2.5 + 10 / 4
print '被除数与除数有一个为浮点数,则结果为浮点数:'
print '2.5 + 10/4 =', 2.5 + 10.0 / 4
print '2.5 + 10/4 =', 2.5 + 10 / 4.0
print '整数除以整数的结果还是整数:'
print '2.5 + 10/4 =',2.5 + 10 / 4
print '被除数与除数有一个为浮点数,则结果为浮点数:'
print '2.5 + 10/4 =', 2.5 + 10.0 / 4
print '2.5 + 10/4 =', 2.5 + 10 / 4.0
2018-05-22
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
print u'中文\n'
print u'中文\n日文\n韩文\n'
print u'''第一行
第二行\n'''
print u''' 静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。
'''
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
print u'中文\n'
print u'中文\n日文\n韩文\n'
print u'''第一行
第二行\n'''
print u''' 静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。
'''
2018-05-22
# -*- coding: UTF-8 -*-
print r'\(~_~)/ \(~_~)/'
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
print r'\(~_~)/ \(~_~)/'
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
2018-05-22
print '1:'
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
print '2:'
t = 'Python was started in 1989 by "Guido".\nPython\'s free and easy to learn.'
print t
print '3:'
a = '''Python was started in 1989 by "Guido".
Python is free and easy to learn.'''
print a
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
print '2:'
t = 'Python was started in 1989 by "Guido".\nPython\'s free and easy to learn.'
print t
print '3:'
a = '''Python was started in 1989 by "Guido".
Python is free and easy to learn.'''
print a
2018-05-22
# -*- coding: UTF-8 -*-
x1 = 1
d = 3
n = 100
x100 = x1+(n-1)*d #通项公式
s = (n*(x1+x100))/2 #前n项和公式
print s
x1 = 1
d = 3
n = 100
x100 = x1+(n-1)*d #通项公式
s = (n*(x1+x100))/2 #前n项和公式
print s
2018-05-22
# -*- coding: UTF-8 -*-
#print 'hello'
'''
print 'hello'
'''
#print 'hello'
'''
print 'hello'
'''
2018-05-22
# -*- coding: UTF-8 -*-
#input code
print '1:'
print 'hello,python'
print '2:'
print 'h'+'e'+'l'+'l'+'o'+','+'p'+'y'+'t'+'h'+'o'+'n'
#input code
print '1:'
print 'hello,python'
print '2:'
print 'h'+'e'+'l'+'l'+'o'+','+'p'+'y'+'t'+'h'+'o'+'n'
2018-05-22
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
sum = sum + x/2
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
sum = sum + x/2
print sum
2018-05-22