最新回答 / 小火星_
raw字符串就是里面的字符不需要转义。转义字符是将反斜杠“\”后面的字符转换成另外的意义。如"\n","n"不代表字母n而作为“换行符”。print r'''Python is created by "Guido".It is free and easy to learn.Let's start learn Python in imooc!'''Python is created by "Guido".It is free and easy to learn.Let's start learn Pytho...
2015-11-18
因为L.pop(2)先删除了Paul,此时列表中仅有三个元素,之后的L.pop(3)就属于超出列表范围了,所以不能执行
2015-11-18
已采纳回答 / 小火星_
假设你想要在一个字符串中包含一个单引号('),那么你该怎么指示这个字符串?例如,这个字符串是What's your name?。你肯定不会用'What's your name?'来指示它,因为Python会弄不明白这个字符串从何处开始,何处结束。所以,你需要指明单引号而不是字符串的结尾。可以通过 转义符 来完成这个任务。你用\'来指示单引号——注意这个反斜杠。现在你可以把字符串表示为'What\'s your name?'。另一个表示这个特别的字符串的方法是"What's your name?",即用双引...
2015-11-18
但是r'...'表示法不能表示多行字符串,也不能表示包含'和 "的字符串
2015-11-17
L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
#print ?
就我一个人是把最后一个注释的嘛?
print L[0]
print L[1]
print L[2]
#print ?
就我一个人是把最后一个注释的嘛?
2015-11-17
运行没有结果
x1 = 1
d = 3
n = 100
x100 = x1 + ( n - 1 ) * d
s = ( x1 + x100 ) * n / 2
print s
x1 = 1
d = 3
n = 100
x100 = x1 + ( n - 1 ) * d
s = ( x1 + x100 ) * n / 2
print s
2015-11-17
print [100*a+10*b+c for a in range(1,10) for b in range(0,10) for c in range(1,10) if a == c]
2015-11-17
已采纳回答 / Perona
range()函数原型是:range(start, end, scan):参数含义:start:计数从start开始。默认是从0开始。例如range(5)等价于range(0, 5);end:技术到end结束,但不包括end.例如:range(0, 5) 是[0, 1, 2, 3, 4]...
2015-11-16
a = 'python'
print 'hello,', a or 'world'
# 因为a 为 True,所以运算结果必定为 True,返回a ,输出“hello,python”
b = ''
print 'hello,', b or 'world'
# 因为b为 False,所以运算结果必定取决于'world',返回'world',输出“hello,world”
print 'hello,', a or 'world'
# 因为a 为 True,所以运算结果必定为 True,返回a ,输出“hello,python”
b = ''
print 'hello,', b or 'world'
# 因为b为 False,所以运算结果必定取决于'world',返回'world',输出“hello,world”
2015-11-16
1. 在计算 a and b 时,如果 a 是 False,则根据与运算法则,整个结果必定为 False,因此返回 a;如果 a 是 True,则整个计算结果必定取决与 b,因此返回 b。
2. 在计算 a or b 时,如果 a 是 True,则根据或运算法则,整个计算结果必定为 True,因此返回 a;如果 a 是 False,则整个计算结果必定取决于 b,因此返回 b。
所以Python解释器在做布尔运算时,只要能提前确定计算结果,它就不会往后算了,直接返回结果。
2. 在计算 a or b 时,如果 a 是 True,则根据或运算法则,整个计算结果必定为 True,因此返回 a;如果 a 是 False,则整个计算结果必定取决于 b,因此返回 b。
所以Python解释器在做布尔运算时,只要能提前确定计算结果,它就不会往后算了,直接返回结果。
2015-11-16
print 2.5 + 10 / 4 # ==>2.5+2 =4.5
print 2.5 + 10.0/4 # ==>2.5+2.5 =5.0
print 2.5 + 10.0/4 # ==>2.5+2.5 =5.0
2015-11-16
# -*- coding: utf-8 -*-
print u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
print u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
2015-11-16