zoukankan      html  css  js  c++  java
  • day04总结

    print("陈少最帅!!!")
    
        输出结果: 陈少最帅!!!
    可以变,不可变数据类型
    #1、可变类型:list,dict
    #在值改变的情况下,id号不变,也就是说内存地址不变,证明就是在改原来内存空间中的值,即原值可变

    #2、不可变类型:int、float、str
    #在值改变的情况下,id号也跟着变了,也就是说内存地址变了,证明不是在改原来内存空间中的值,
    # 而是申请了新的内存空间,产生了新的值,即原值不可变
    # x=10
    # print(id(x))
    # x=11
    # print(id(x))


    # x=10.3
    # print(id(x))
    # x=11.4
    # print(id(x))

    # x="abc"
    # print(id(x))
    # x="aBc"
    # print(id(x))

    # l1=[111,"aaaa"]
    # print(id(l1))
    # l1[0]=222222
    # print(l1)
    # print(id(l1))

    # dic={'k1':111,'k2':222}
    # print(id(dic))
    # dic['k1']="abc"
    # print(dic)
    # print(id(dic))


    # 字典的value可以是任意类型,但是字典的key必须是不可变类型
    # dic={1111111:"abc","k2":"def",3.1:'aaa'}
    # print(dic[1111111])


    # 下面写法推荐使用列表代替
    # dic={0:'egon',1:"egon1",2:"egon3"}

    # print(dic[0])
    # print(dic[1])
    # print(dic[2])

    # 了解:不可哈希类型就是可变类型,可哈希类型就是不可变类型
    # dic={[1,2,3]:"abc"}



    赋值运算符补充
    # 1、增量赋值
    # age=18
    # age += 1
    # print(age)

    # 2、链式赋值
    # x=10
    # y=x
    # z=y

    # z = y = x = 10
    # print(x, y, z)
    # print(id(x), id(y), id(z))

    # 3、交叉赋值
    # m = 111
    # n = 222

    # temp=m
    # m=n
    # n=temp
    # m, n = n, m
    # print(m, n)

    # 4、解压赋值
    # salaries = [1.1, 2.2, 3.3, 4.4, 5.5]
    # mon0 = salaries[0]
    # mon1 = salaries[1]
    # mon2 = salaries[2]
    # mon3 = salaries[3]
    # mon4 = salaries[4]

    # mon0, mon1, mon2, mon3, mon4 = salaries
    # print(mon0)
    # print(mon1)
    # print(mon2)
    # print(mon3)
    # print(mon4)

    # 变量名的个数必须与包含的值的个数相同,多一个不行,少一个也不行
    # mon0, mon1, mon2, mon3, mon4, mon5 = salaries
    # mon0, mon1, mon2, mon3 = salaries

    # mon0, mon1, mon2, *_ = salaries
    # print(mon0)
    # print(mon1)
    # print(mon2)
    # print(_)

    # *_, x, y, z = salaries
    # print(x)
    # print(y)
    # print(z)

    # x, *_, z = salaries
    # print(x)
    # print(z)


    # dic={"k1":111,"k2":222}
    # del dic['k1']
    # print(dic)
    # dic["kkk"]=111
    # print(dic)

    # 对于字典来说解压赋值取出来的是字典的key
    # dic = {"k1": 111, "k2": 222}
    # x, y = dic
    # print(x, y)


    # 了解
    # a,b,c,d,e="hello"
    # print(a,type(a))
    # print(b)
    # print(c)
    # print(d)


    身份运算
    # 身份运算is与==

    # ==判断的是值是否相等
    # x = ['a', 'b']
    # y = ['a', 'b']
    # print(x == y)

    # is判断的是id是否相等
    # print(id(x))
    # print(id(y))
    # print(x is y)

    # 分析:
    # is判断的结果为True,即二者的id一样,即二者内存地址一样,即二者就是一个东西,即值一定相等
    # 如果==判断的结果为True,即二者的值一样,那么二者的内存地址可能不一样

    # x=None
    # y=None
    # # print(x == None)
    # print(x is None)
    # print(x is y)

    # print((10 > 3) is True)
    # print((10 > 3) == True)
    # x=True
    # y=True
    # z=True
    # print(id(x))
    # print(id(y))
    # print(id(z))

    # 结论:如果要变量一个变量是否等于None、True、False,推荐使用is去判断

    流程控制 if 判断

    """
    1、什么是if判断
    判断 条件1 并且 条件2:
    做什么事。。。
    否则:
    做什么事。。。

    2、为何要有if判断
    为了控制计算机能够像人一样去完成判断的过程

    3、如何用if判断
    """
    # 1、介绍
    # print('start....')
    # if 3 != 3 and 10 > 8:
    # print("条件成立1")
    # print("条件成立2")
    # print("条件成立3")
    # else:
    # print("条件不成立1")
    # print("条件不成立2")
    # print("条件不成立3")
    # print('end....')

    # if判断完整的语法
    """
    if 条件1:
    子代码块1
    elif 条件2:
    子代码块2
    elif 条件3:
    子代码块3
    ...
    else:
    子代码块
    """

    # 2、必须要有的是if,只有一个if是可以的
    # inp_name=input('你的名字: ')
    # if inp_name == "egon":
    # print('输入正确')
    #
    # print('其他代码')

    # 3、if+elif
    # inp_name=input('你的名字: ')
    # if inp_name == "egon":
    # print('您的身份是超级vip')
    # elif inp_name == "张三":
    # print('您的身份是钻石vip')
    # elif inp_name == "李四":
    # print('您的身份是铂金vip')
    #
    # print('其他代码')

    # 4、if+else
    # inp_name = input('你的用户名: ')
    # inp_pwd = input('你的密码: ')
    #
    # if inp_name == "egon" and inp_pwd == "123":
    # print('登录成功')
    # else:
    # print("刚刚输入的用户名或密码错误")
    #
    # print('其他代码')

    # 5、if+elif+else
    """
    如果:成绩>=90,那么:优秀

    如果成绩>=80且<90,那么:良好

    如果成绩>=70且<80,那么:普通

    其他情况:很差
    """
    # score = input("请输入您的成绩: ")
    # score = int(score)
    # if score >= 90:
    # print("优秀")
    # elif score >= 80:
    # print("良好")
    # elif score >= 70:
    # print("普通")
    # else:
    # print("很差")


    # 补充
    # age = 19
    # age >= 18 and age <= 20
    # print(20 >= age >= 18)
    # print(18 <= age <= 20)

    # if判断嵌套if
    print('ok0')
    if 10 > 3:
    if 1 == 1:
    print('ok1')
    print('ok2')
    print('ok3')
    print('ok4')
     
  • 相关阅读:
    Rotation issue in XCode 4.5 and iOS 6.0
    Core Data on iOS 5 Tutorial: How To Work with Relations and Predicates
    How To Synchronize Core Data with a Web Service – Part 2
    Unit Testing in Xcode 4 – use OCUnit and SenTest instead of GHUnit
    Migrate old project to ARC
    Core Data on iOS 5 Tutorial: Getting Started
    How To Draw Graphs with Core Plot, Part 2
    How To Use NSOperations and NSOperationQueues
    How To Save Your App Data With NSCoding and NSFileManager
    What's New in iOS
  • 原文地址:https://www.cnblogs.com/Knge/p/13043665.html
Copyright © 2011-2022 走看看