为了账号安全,请及时绑定邮箱和手机立即绑定
  • 目前CPU硬件提升,运行速度慢在平常情况下,就不是问题。

    查看全部
    0 采集 收起 来源:Python简介

    2024-03-13

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


    def f1( **kwargs ):

        L_names = kwargs.get('name')

        L_gender = kwargs.get('gender')

        L_age = kwargs.get('age')

        i = 0

        while i < len(L_names) :

            temp1 = 'Name is {0},gender is {1},age is {2}'

            print(temp1.format(L_names[i],L_gender[i],L_age[i] ))

            i = i +1


    f1(name = ['Ali','Bok','Pse'], gender = ['Male','Male','Fmale'],age = [10,37,26])

    查看全部
  • 输出结果
    hello python

    hello world
    查看全部
  • a="python"

    print('hello,', a or 'world')

    b=''

    print('hello,', b or 'world')

    查看全部
  • Python之if-else语句

    score = 59
    if score < 60:
        print('抱歉,考试不及格')
    else:
        print('恭喜你,考试及格')

    查看全部
  • L=['Alice', 66, 'Bob', True, 'False', 100]
    index=0
    for item in L:
    if index%2==0:
    print(L[index])
    index+=1
    查看全部
  • L = ['Chinese:', 92, 'Math:', 75 ,'English:', 99]
    print(L)
    查看全部
  • Python之if语句

    score = 59
    if score < 60:
        print('抱歉,考试不及格')
    # ==> 抱歉,考试不及格


    可以看到print('抱歉,考试不及格')这行代码明显比上一行代码缩进了,这是因为这行代码是if判断的一个子分支,因此需要缩进,在Python规范中,一般使用4个空格作为缩进

    在if语句的最后,有一个冒号:,这是条件分支判断的格式,在最后加入冒号:,表示接下来是分支代码块

    查看全部
    0 采集 收起 来源:Python之if语句

    2024-03-06

  • Python的字符串切片

    按照位置取字符串的方式使用中括号[ ]访问

    s = 'ABC'
    a = s[0] # 第一个
    b = s[1] # 第二个
    c = s[2] # 第三个
    print(a) # ==> A
    print(b) # ==> B
    print(c) # ==> C

    查看全部
  • age1=18
    if age1>=18:
    print('adult')
    else:
    print('teenager')

    age2=17
    if age2>=18:
    print('adult')
    else:
    print('teenager')
    查看全部
  • ddq_age=19
    if ddq_age>=19:
    print('dongdongqiang is adult,his age is '+str(ddq_age))
    查看全部
    0 采集 收起 来源:Python之if语句

    2024-03-06

  • template='life is {1},you need {0}'
    result=template.format('python','short')
    print(result)

    template1='life is {s},you need {p}'
    ss='short'
    pp='python'
    result1=template1.format(s=ss,p=pp)
    print(result1)
    查看全部
  • print(r''''\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.' ''')


    raw字符的作用是让转义字符 \ 无效
    查看全部
  • 字符串format

    方式1:template = 'Hello {}'
    world = 'World'
    result = template.format(world)
    print(result) # ==> Hello World


    方式2:
    template = 'Hello {3}, Hello {2}, Hello {1}, Hello {0}.'
    result = template.format('World', 'China', 'Beijing', 'imooc')
    print(result) # ==> Hello imooc, Hello Beijing, Hello China, Hello World.

     

    方式3:

    template = 'Hello {w}, Hello {c}, Hello {b}, Hello {i}.'
    world = 'World'
    china = 'China'
    beijing = 'Beijing'
    imooc = 'imooc'
    result = template.format(w = world, c = china, b = beijing, i = imooc)
    print(result) # ==> Hello World, Hello China, Hello Beijing, Hello imooc.

    查看全部
  • 多行字符串转义

    r'''字符串1

    字符串2

    字符串3'''

    查看全部

举报

0/150
提交
取消
课程须知
如果您了解程序设计的基本概念,会简单使用命令行,了解中学数学函数的概念,那么对课程学习会有很大的帮助,让您学起来得心应手,快速进入Python世界。
老师告诉你能学到什么?
通过本课程的学习,您将学会搭建基本的Python开发环境,以函数为基础编写完整的Python代码,熟练掌握Python的基本数据类型以及list和dict的操作,灵活使用流程控制语句。

微信扫码,参与3人拼团

意见反馈 帮助中心 APP下载
官方微信
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!