简介 目录 评价 推荐
  • 宽Coo1 3天前
    逐行拆解核心逻辑,简单易懂:

    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的人的名字和分数吗?
    0赞 · 0采集
  • 慕斯2221966 3天前

    # coding: utf-8

    result=r'''这是一句中英文混合的Python字符串:

    \Hello World\ '''

    print(result)

    0赞 · 0采集
  • 慕斯2221966 3天前

    # 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)

    0赞 · 0采集
  • 慕斯2221966 3天前

    # 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.')

    0赞 · 0采集
  • 慕丝7346314 2025-11-30

    print(r'''\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.''')

    0赞 · 0采集
  • 慕丝7346314 2025-11-30

    print('special string: \', \", \\, \\\\, \\n, \\t')

    0赞 · 0采集
  • 慕丝7346314 2025-11-30

    \n表示换行
    \t 表示一个制表符
    \\表示 \ 字符本身

    如果字符串既包含'又包含"怎么办?

    这个时候,就需要对字符串中的某些特殊字符进行“转义”,Python字符串用\进行转义。

    要表示字符串Bob said "I'm OK"
    由于'和"会引起歧义,因此,我们在它前面插入一个\表示这是一个普通字符,不代表字符串的起始,因此,这个字符串又可以表示为

    'Bob said \"I\'m OK\".'

    注意:转义字符 \不计入字符串的内容中。

    0赞 · 0采集
  • 慕丝7346314 2025-11-30

    与运算

    只有两个布尔值都为 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

    0赞 · 0采集
  • 慕哥8071433 2025-11-29
    print(imma)
    0赞 · 0采集
  • 精慕门2058880 2025-11-16
    理论上,所有的递归函数都可以写成循环的方式,但循环的逻辑不如递归清晰。
    0赞 · 0采集
  • 慕无忌7593737 2025-11-14
    这里有几个需要注意的地方:

    可以看到print('抱歉,考试不及格')这行代码明显比上一行代码缩进了,这是因为这行代码是if判断的一个子分支,因此需要缩进,在Python规范中,一般使用4个空格作为缩进
    在if语句的最后,有一个冒号:,这是条件分支判断的格式,在最后加入冒号:,表示接下来是分支代码块
    0赞 · 0采集
  • 慕九州1304478 2025-11-06
    round函数(num,2)
    0赞 · 0采集
  • 王琴琴6325007 2025-10-27
    print(type(3.1415926))#<class'float'>
    print(pyte('Learn Python in important.'))#<class 'str'>
    print(pyte(100))#<class 'int'>
    print(pyte(0b1101))#<class 'int'>
    print(0b1101)#输出 13,验证二进制转十进制
    0赞 · 0采集
  • web新星 2025-10-20

    地板除

    10//3 # ==> 3

    0赞 · 0采集
  • 慕斯卡5227843 2025-10-15

    else if 可以用elif代替更简单方便。

    写条件的时候要注意逻辑清晰。

    0赞 · 0采集
  • 慕斯卡5227843 2025-10-15

    打印代码需要缩进

    if语句后必须要有“:”

    0赞 · 0采集
  • 慕标5279932 2025-10-15

    s[0:4] s中的第一个字符到第五个字符,不包括第五个字符

    s[2:6] s中的第三个字符到第七个字符,不包括第七个字符

    0赞 · 0采集
  • 慕雪7579645 2025-10-15

    字符串索引

    s[i]

    字符串切片

    s[i]左闭右开

    0赞 · 0采集
  • 慕运维6303068 2025-10-15

    字符串索引 s[i]

    字符串切片 s[i:j]左闭右开 

    0赞 · 0采集
  • 慕莱坞8378796 2025-10-15

    字符串索引

    s[i]

    字符串切片

    s[0:i]左闭右开

    0赞 · 0采集
  • 慕的地6321687 2025-10-15

    字符串索引

    s[i]

    字符串切片

    s[i:j]左闭右开

    0赞 · 0采集
  • 慕标5279932 2025-10-15

    字符串索引

    s{i}

    字符串切片

    s{i:j} 左闭右开

    0赞 · 0采集
  • 慕虎5498511 2025-10-15

    s[i]左闭右开

    从0开始切片,最后一个字符不取

    0赞 · 0采集
  • 慕斯卡5227843 2025-10-15

    字符串的索引

    s[i]

    字符串的切片

    s[i:j]左闭右开

    0赞 · 0采集
  • 慕数据6409079 2025-10-15

    s = 'ABCDEFGHIJK'
    abcd = s[0:4] # 取字符串s中的第一个字符到第五个字符,不包括第五个字符
    print(abcd) # ==> ABCD
    cdef = s[2:6] # 取字符串s中的第三个字符到第七个字符,不包括第七个字符
    print(cdef) # ==> CDEF

    0赞 · 0采集
  • 慕桂英6267281 2025-10-15

    字符串的索引

    s[i]

    字符串切片

    s[i:j] 左闭右开

    0赞 · 0采集
  • 慕容6382583 2025-10-15

    字符串索引

    s[i]

    字符串切片

    s[i:j] 左闭右开

    0赞 · 0采集
  • 112300702王书晨 2025-10-12

    任务

    编写一个函数,它接受关键字参数names,gender,age三个list,分别包含同学的名字、性别和年龄,请分别把每个同学的名字、性别和年龄打印出来。

    参考答案:

    def info(**kwargs):
       names = kwargs['names']
       gender_list = kwargs['gender']
       age_list = kwargs['age']
       index = 0
       for name in names:
           gender = gender_list[index]
           age = age_list[index]
           print('name: {}, gender: {}, age: {}'.format(name, gender, age))
           index += 1

    info(names = ['Alice', 'Bob', 'Candy'], gender = ['girl', 'boy', 'girl'], age = [16, 17, 15])

    0赞 · 0采集
  • 112300702王书晨 2025-10-11

    任务

    请定义一个 greet() 函数,它包含一个默认参数,如果没有传入参数,打印 Hello, world.,如果传入参数,打印Hello, 传入的参数内容.

    def greet(name='world'):
       print ('Hello, ' + name + '.')

    greet()
    greet('Alice')

    0赞 · 0采集
  • 112300702王书晨 2025-10-11

    任务

    已知两个集合s1、s2,请判断两个集合是否有重合,如果有,请把重合的元素打印出来。

    s1 = set([1, 2, 3, 4, 5])
    s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])

    参考答案:

    s1 = set([1, 2, 3, 4, 6, 8, 10])
    s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
    flag = s1.isdisjoint(s2)
    if not flag:
       for item in s1:
           if item not in s2:
               continue
           print(item)

    0赞 · 0采集
数据加载中...
开始学习 免费