为了账号安全,请及时绑定邮箱和手机立即绑定

4小时入门Python开发

  • # coding=utf-8

    movies = []

    mov = {"year":1902,"title":"月球之旅","director":"乔治斯·梅利斯","description":"历史上第一部科幻电影"}

    movies.append(mov)

    mov1 = {"year":1916,"title":"海底两万里","director":"查理德·弗莱彻","description":"第一步水下拍摄的科幻电影"}

    movies.append(mov1)


    y = 1916

    for m in movies:

        if y == m["year"]:

            print(m["year"])

            print(m["title"])

            print(m["director"])

            print(m["description"])

    http://img1.mukewang.com/609553bc000115d402960128.jpg

    查看全部
  • # coding=utf-8

    col1 = ["玩具","饮料","唇彩"]

    col2 = ["手办","卡片","唇彩"]

    col3 = ["卡片","饮料","手套"]

    row = [col1,col2,col3]


    for col in row:

        for box in col:

            print(box)

        print("==============")

    http://img3.mukewang.com/609550ad000110a603300258.jpg

    查看全部
    0 采集 收起 来源:嵌套循环

    2021-05-07

  • #while

    # coding=utf-8

    n = 100

    while n < 1000:

        i = int(n/100)

        j = int(n/10)%10

        k = n %10

        if n == i*i*i+j*j*j+k*k*k:

            print(n,end="")

            print("是水仙花数")

        n = n+1

    http://img3.mukewang.com/60954e0d00018a1302630124.jpg

    查看全部
  • # coding=utf-8


    for n in range(100,1000):

        i = int(n/100)

        j = int(n/10)%10

        k = n %10

        if n == i*i*i+j*j*j+k*k*k:

            print(n,end="")

            print("是水仙花数")

    http://img2.mukewang.com/60954d830001eacc02230125.jpg

    查看全部
  • #range 左闭右开

    # coding=utf-8

    for i in range(10,15):

        print(i)

    http://img2.mukewang.com/60954b6b0001f15a02440164.jpg

    查看全部
  • # coding=utf-8

    books = ["三国演义","水浒传","西游记"]

    for book in books:

        if book != "西游记":

            print(book)

    http://img1.mukewang.com/60954ac80001042202470093.jpg

    查看全部
  • # coding=utf-8

    i = 1

    res = 3

    while i <= 10 :

        print(res)

        res = res * 3

        i = i + 1 

    print("循环结束")

    http://img2.mukewang.com/609549930001bc7603940231.jpg

    查看全部
  • # coding=utf-8

    i= 0

    while i < 4:

        print(i*100)

        i = i+1

    print("循环结束")


    http://img1.mukewang.com/609548c50001325a02640168.jpg

    查看全部
  • 列表字典组合

    # coding=utf-8

    stus = []

    stu1 = {"no":"111","name":"张三","age":23,"nation":"汉","birthday":"1998-01-01","father":{"name":"张建国","company":"中国移动","job":"客户经理"},"mother":{"name":"吴燕玲","company":"师大附中","job":"语文老师"}}

    stus.append(stu1)

    print(stus)

    name = stus[-1]["name"]

    print(name)


    stu2 = {"no":"112","name":"李四","age":23,"nation":"汉","birthday":"1998-01-01","father":{"name":"李建国","company":"中国联通","job":"客户经理"},"mother":{"name":"张丽丽","company":"人民医院","job":"外科医生"}}

    stus.append(stu2)

    print(stus)


    name = stus[-1]["name"]

    print(name)

    fatherName = stus[-1]["father"]["name"]

    print(fatherName)

    http://img1.mukewang.com/6095464100019eea19080167.jpg

    查看全部
  • 列表字典组合

    # coding=utf-8

    stus = []

    stu1 = {"no":"111","name":"张三","age":23,"nation":"汉","birthday":"1998-01-01","father":{"name":"张建国","company":"中国移动","job":"客户经理"},"mother":{"name":"吴燕玲","company":"师大附中","job":"语文老师"}}

    stus.append(stu1)

    print(stus)

    name = stus[-1]["name"]

    print(name)


    stu2 = {"no":"112","name":"李四","age":23,"nation":"汉","birthday":"1998-01-01","father":{"name":"李建国","company":"中国联通","job":"客户经理"},"mother":{"name":"张丽丽","company":"人民医院","job":"外科医生"}}

    stus.append(stu2)

    print(stus)


    name = stus[-1]["name"]

    print(name)

    fatherName = stus[-1]["father"]["name"]

    print(fatherName)

    http://img1.mukewang.com/6095464100019eea19080167.jpg

    查看全部
  • 列表字典组合

    # coding=utf-8

    stus = []

    stu1 = {"no":"111","name":"张三","age":23,"nation":"汉","birthday":"1998-01-01","father":{"name":"张建国","company":"中国移动","job":"客户经理"},"mother":{"name":"吴燕玲","company":"师大附中","job":"语文老师"}}

    stus.append(stu1)

    print(stus)

    name = stus[-1]["name"]

    print(name)


    stu2 = {"no":"112","name":"李四","age":23,"nation":"汉","birthday":"1998-01-01","father":{"name":"李建国","company":"中国联通","job":"客户经理"},"mother":{"name":"张丽丽","company":"人民医院","job":"外科医生"}}

    stus.append(stu2)

    print(stus)


    name = stus[-1]["name"]

    print(name)

    fatherName = stus[-1]["father"]["name"]

    print(fatherName)

    http://img1.mukewang.com/6095464100019eea19080167.jpg

    查看全部
  • #键值对存储key不能重复,value可以重复

    # coding=utf-8

    lisa = {"name":"Lisa","age":23}

    print(lisa)

    print(lisa["age"])

    lisa["age"] = 26

    lisa["height"] = 166

    print(lisa)

    lisa.pop("age")

    print(lisa)

    http://img4.mukewang.com/60953fe9000134f203950149.jpg

    查看全部
  • 左闭右开[0:2]取第一个和第二个

    反向索引最后一个下标是-1

    # coding=utf-8

    books = ["红楼梦","三国演义","水浒传","西游记","聊斋志异"]

    print(books[0:4])

    print(books[0:-1])

    http://img.mukewang.com/6065e81700013a5a05740160.jpg

    查看全部
  • # coding=utf-8

    books = ["红楼梦","三国演义","水浒传","西游记","聊斋志异"]

    print(books[0])

    http://img.mukewang.com/6065e6ba00013c5004110107.jpg

    查看全部
  • int取整

    %取余

    # coding=utf-8

    n=154

    a=int(n/100)

    b=int(n%100/10)

    c=n%10

    print(a)

    print(b)

    print(c)

    re=a*a*a+b*b*b+c*c*c

    if n==re:

    print(n,end="")

    print("是水仙花数")

    else:

    print(n,end="")

    print("不是水仙花数")


    154除以100取余54,54除以10等于5.4取整为5

    http://img4.mukewang.com/6065e3fe0001a39705290138.jpg

    查看全部
首页上一页123下一页尾页

举报

0/150
提交
取消

邀请2人参与享拼团价

  • ¥88.00

    单独购买

  • ¥1.00

    3人拼团

课程须知
1、电脑下载安装主流浏览器Google Chrome浏览器或360极速浏览器 2、有慕课网官网https://class.imooc.com/ 3、课程需要的在线编译环境:https://wiki.imooc.com/section/morerun/1472.html
老师告诉你能学到什么?
1、掌握Python的基础知识 2、学会用Python解决实际问题 3、了解Python开发思维

微信扫码,参与3人拼团

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

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