-
tuple是固定不变的,一旦变成tuple,tuple中的每一个元素都不可被改变,同时也不能再往tuple中添加数据,而list是可以的。
查看全部 -
insert()方法需要两个参数,分别是需要插入的位置,以及需要插入的元素。查看全部
-
append()方法总是将元素添加到list的尾部。查看全部
-
我这就学完这个课程啦查看全部
-
num = 10 / 3
print(num) # ==> 3.3333333333333335
# 使用round保留两位小数
round(num, 2) # ==> 3.33使用round()函数可以选择保留几位小数
查看全部 -
逐行拆解核心逻辑,简单易懂:
1. d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
定义一个字典 d ,键(key) 是人名(Alice/Bob/Candy),值(value) 是对应人的分数列表。
2. for key in d.values():
遍历字典 d 的所有值(value),每次循环把一个值(这里是分数列表)赋值给变量 key (变量名可改,叫 value 更易理解)。
3. print(key)
每次循环打印当前获取到的字典值(即分数列表),所以依次输出3个人的分数列表,和示例结果一致。
核心重点: d.values() 是字典专属方法,作用是直接提取字典里所有的“值”,而非默认的“键”。
需要我帮你修改代码,实现只打印分数都大于60的人的名字和分数吗?查看全部 -
# coding: utf-8
result=r'''这是一句中英文混合的Python字符串:
\Hello World\ '''
print(result)
查看全部 -
# Enter a code
template='lif is {a} , you need {b}'
c='short'
d='Python'
result = template.format(a=c,b=d)
print(result)
template2='lif is {0} , you need {1}'
result2=template2.format('long','happy')
print(result2)
查看全部 -
# Enter a code
a=r'\(~_~)/'
print(a)
b='''line1
line2\nline3'''
print(b)
c='''hello TOM
Hello JIMY\nHELLO 'lisa'''
print(c)
d=r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
print(d)
print('\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.')
查看全部 -
print(r'''\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.''')
查看全部 -
print('special string: \', \", \\, \\\\, \\n, \\t')
查看全部 -
\n表示换行
\t 表示一个制表符
\\表示 \ 字符本身如果字符串既包含'又包含"怎么办?
这个时候,就需要对字符串中的某些特殊字符进行“转义”,Python字符串用\进行转义。
要表示字符串Bob said "I'm OK"
由于'和"会引起歧义,因此,我们在它前面插入一个\表示这是一个普通字符,不代表字符串的起始,因此,这个字符串又可以表示为'Bob said \"I\'m OK\".'
注意:转义字符 \不计入字符串的内容中。
查看全部 -
与运算
只有两个布尔值都为 True 时,计算结果才为 True。
True and True # ==> True
True and False # ==> False
False and True # ==> False
False and False # ==> False或运算
只要有一个布尔值为 True,计算结果就是 True。
True or True # ==> True
True or False # ==> True
False or True # ==> True
False or False # ==> False非运算
把True变为False,或者把False变为True:
not True # ==> False
not False # ==> True查看全部 -
print(imma)查看全部
-
理论上,所有的递归函数都可以写成循环的方式,但循环的逻辑不如递归清晰。查看全部
举报