The first chapter python

About python

python

Chapter One

  1. python History

    I was born in 2004

    python 2:

    The source code is not uniform, there are duplicate function code

    python 3:

    Source unity, there is no duplication of function code

  2. What is a python programming language

    Use compiled and interpretive programming language to distinguish

    Compiled: translated only once (on behalf c)

    Advantages: fast execution

    Disadvantages: slow development

    Interpreted: Progressive translation (on behalf of Python)

    Cons: Slow execution

    Pros: Fast Development

  3. python species

    cpython python ironpython pypy

    Official download is cpython

  4. Variables - Output

    变量:
    # 什么是变量?
    #    是将一个临时的值存储在内容中(存储中间值)
    # 变量能做什么?
    #    可以多次重复使用
    # 变量在哪用怎么用?
    # 在程序中频繁使用
    
    print(35+56) # 打印-输出
    print((35+56)*2) # 打印-输出
    print(((35+56))*2) # 打印-输出
    
    a = 35+56
    print(a)
    b = a*2
    print(b)
    print(1+a)
    
    # a = 1 #声明变量
    # a #变量的名字
    # = #赋值
    # 1 #值 
    定义变量内存图:
    # a = "藿香正气水" #声明变量
    # b = "藿香正气水"

    变量定义规则:
    # 1.由数字,字母和下划线组成
    # 2.不能以数字开头
    # 3.不能使用python中关键字
    #    关键字(蓝色字体)
    # 4.不能使用中文和拼音
    # 5.区分大小写
    # 6.变量名要具有描述性
    # 7.推荐写法
    #    7.1驼峰体  ageofoldboy = 98
    #    7.2下划线  age_of_old_box = 98(官方推荐)
    
    变量的小高级:
    age = 18
    age1 = 19
    age2 = age # age2 = 18
    age = 20
    print(age,age1,age2)

    从右往左执行:
    a = 4
    b = a + 6 # 在声明变量的时候先执行变量右边
    print(b)

  5. constant

    常量:
    # 什么是常量?
    #     常量是不变的量
    # 常量能做什么?
    
    # 常量在哪里用?
    #     在配置文件中声明使用
    # 常量不建议修改
    # 变量定义规则
    # 大写开头
    
    ID = 1869662919
  6. Note

    注释:
    #注释是什么?
    #    注释说明自己的代码
    # 单行 注释(当行注释)# 这是注释
    # 多行 注释  '''这是多行注释'''(必须无缩进)
    '''
    这是注释
    
    '''
    # """  '''  这是注释  '''   """
    """
    '''
    这是注释
    '''
    注释
    '''
    这是注释2
    '''
    """
    # 被注释的内容不会被执行
    #print("这是注释")
    
  7. Basic data types

    什么是基础类型?
    #    整型:  int  (数字)
    #    字符串:str  用引号引起来的(字母、汉字)
    #    布尔型:bool (True、False)
    基础类型是怎么用的?
    #    数字:用于计算和比较
    #    字符串:
    #    加法--同是字符串才能相加
    #    乘法--字符串与数字才能相乘
    #    布尔型:用于返回真假值,用于判断
    #    True--真
    #    False--假
    #基础类型在哪里用?
    
    # 56  整型int
    # 56 + 3
    # 56 - 2
    # 56 * 3
    # 56 / 4
    
    
    # "您好"字符串str
    
    a = "您好"
    b = "python"
    c = "呀"
    print(a + b + c) #字符串拼接
    
    d = "您好"
    print(d * 8) #字符串乘法运算
    
    a = '''您好'''
    b = '我好'
    c = """大家好"""
    d = '''
    您好
    python
    '''
    # 引号直接互相使用,成对出现
    e = "my name's meet"
    f = 'my name is "meet"'
    i = """ my name's "meet" """
    print(a,b,c,d,e,f,i)
    
    
    # 布尔值 bool
    # True 对
    # False 错
    
    print(3<0)
  8. Entry

    输入:
    # 用户交互是什么?
    #    input () 用户交互
    #    input ("提示语句")
    # 做什么
    # 怎么用
    #    py3中 input获取到的都是字符串
    #    int()--将字符串中的数字转换成整型
    #    type()--查看类型
    
    print(input ("请输入账户,然后回车"))
    
    a = input("请输入账户,然后回车")
    print(a)# 输入什么,则输出什么
    
    a = input("请输入账户,然后回车")
    print(a + "哒")# 输人什么,则输出什么,再输出哒
    
    # type()查看变量类型
    a = input("请输入账户,然后回车")
    print(a,type(a))# 输入什么,则输出什么,再输出class为对应的类型
    
    a = input("请输入")
    print(a + 5)# 提示错误,5应为字符串类型
    
    a = input("请输入")
    print(a + "5")# 输出55
    
    # 将字符串中的数字转换成整型
    a = input("请输入")
    print(int(a) + 5)# 输入5,输出10
  9. Flow control statements: if

    # if -如果 在python中是关键字
    # if True 如果是真的,输出真的
    
    # 单if
    # 关键字 空格 条件 冒号(表示语句完成)
    # 缩进(4个空格)   结果
    if 3>2:
        a = input(">>>")
        print(a)# 输出>>>
    
    if 3>2:
        print(1)# 输出1
    
    if 3>2:
        print(3)
    print(2)# 输出132
    
    print(1)
    if 3<2:
        print(3)
    print(2)# 输出12

    # if else 二选一
    #if 空格 条件 冒号
    #缩进 结果
    #else 冒号
    #缩进 结果
    
    if 3>2:
        print(1)
    else:
        print(2)#输出1
    
    if 3<2:
        print(1)
    else:
        print(2)#输出2
    
    print(5)
    if 3>2:
        print(1)
    else:
        print(2)
    print(6)#输出526
    
    ![](https://img2018.cnblogs.com/blog/1729999/201907/1729999-20190704213008086-1167933370.png)
    
    # if elif elif 多选一或零
    #
    if 3>2:# 如果
        print("A")
    elif 3<8:#再如果
        print("B")
    elif 5<0:
        print("C")# 输出A
    
    if 3<2:
        print("A")
    elif 3<8:
        print("B")
    elif 5<0:
        print("C")# 输出B
    
    if 3<2:
        print("A")
    elif 3<8:
        print("B")
    elif 5<0:
        print("C")# 输出C
    
    if 3<2:
        print("A")
    elif 3>8:
        print("B")
    elif 5<0:
        print("C")# 输出无内容,均为错误
    
    print(110)
    if 3<2:
        print("A")
    elif 3>6:
        print("B")
    elif 5>0:
        print("C")
    print(112)# 输出110 C 112

    # if elif else 多选一
    if 3 == 2:
        print(1)
    elif 3<2:
        print(3)
    elif 3>10:
        print(4)
    else:
        print(9)# 输出9
    
    if 3 == 3:
        print(1)
    elif 3<2:
        print(3)
    elif 3>10:
        print(4)
    else:
        print(9)# 输出1

    # if if if 多选
    if 3>2:
        print("A")
    if 3<6:
        print("B")# 输出AB
    
    if 3>2:
        print("A")
    print(123)
    if 3<6:
        print("B")# 输出A123B

    # if 嵌套
    sex = "女"
    age = "25"
    if sex == "女":
        if age == 25:
            print("请进")
        else:
            print("不合适此职位")
    else:
        print("需要女生才合适")# 条件成立,输出请进

    练习:
    # 1.用户输入账号
    # 2.用户输入密码
    # 3.判断用户的账号是不是Alex
    # 4.如果账号是Alex再继续判断密码是不是Alex
    # 5.如果账号正确密码错误提示密码错误
    # 6.如果账号正确密码错误提示密码错误
    # 7.如果账号错误提示账号错误
    
    user = input("请输入账号:")
    pwd = input("请输入密码:")
    if user == "alex":
        if pwd == "alex":
            print("alex is a good boy")
        else:
            print("密码错误")
    else:
        print("账号错误")
    
    
    # and和and 前边的内容为真并且and后边的内容为真才为真
    user = input("请输入账号:")
    pwd = input("请输入密码:")
    if pwd == "alex" and user == "alex":
        print("alex is a good boy")
    else:
        print("用户名或密码错误")

    Summarize today

    1. python History

      python2 difference and 3

    2. python is interpreted programming language

    3. python species of
      Cpython jtyhon ironpython pypy
      official download cpython

    4. variable

      Naming Rules

    5. constant

      Variable name in all caps, without modification

    6. Note

      Single-line comments, Multiline comments

    7. Basic data types

    int - integer (numbers) are calculated and compared

    Str- string (letters, characters)

    bool- Boolean value for determining (True, False)

    1. User interaction

      input()

      Content is of type string

    2. Flow control statements

      Single if

      if else a second election

      if elif elif one or a plurality of selected zero

      if elif elif else is selected from a plurality of

      if if if multiple-choice or more than zero

      if multiple layers of nested judge wrote three general recommendations

    3. Other knowledge

      And front and rear and only real and true are true

      type View data types

      Int ( "5") to convert the string to integer 5

      str (5) to convert an integer to a string

      Are equal before and after the determination ==

Guess you like

Origin www.cnblogs.com/zhangshan33/p/11135051.html