• python笔录第一周


    赋值打印,注释,各种循环语句

    name = "您好,世界"
    msg = "i'm alex li"

    print(name)
    print(msg)

    #单行注释
    """
    多行注释
    """

    ---------------------------------------------------------------------

    三种输出方式:
    一:
    拼接方式,不推荐使用,每次都要开辟新内存

    二:
    info2 = '''
    ---- info of {_name}----
    name:{_name}
    age:{_age}
    job:{_job}
    salary:{_salary}
    '''.format(_name = name,
    _age = age,
    _job = job,
    _salary = salary)
    print(info2)
    三:
    info3 = '''
    ---- info of {0} ----
    name:{0}
    age:{1}
    job:{2}
    salary:{3}
    '''.format(name, age, job, salary)
    print(info3)

    ---------------------------------------------------------------------

    条件判断:

    import getpass
    #密文导入框架(终端显示)

    #存密码
    _username = 'zhou'
    _password = 'abc123'
    username = input("username:")
    #password = getpass.getpass("password:")
    password = input("password:")


    #if else逻辑
    #else强制缩进
    if _username == username and _password == password:
    #if的子代码
    print("welcome to user {name} python".format(name=username))
    else:
    #else的子代码
    print("Invalid username or password!")

    print("我的Tina")
    ---------------------------------------------------------------------
    while循环:
    count = 0
    while True:
    print("count:", count)
    count = count + 1 #count += 1

    if count == 10 :
    break

    ---------------------------------------------------------------------
    三次输入练习:
    age_of_oldboy = 56;

    count = 0
    while count < 3:

    guess_age = int(input("guess age:"))

    if guess_age == age_of_oldboy :
    print("YES,you got it")
    elif guess_age > age_of_oldboy :
    print("think smaller...")
    else:
    print("think bigger...")
    count += 1
    print("count:", count)

    else:
    print("对不起,您的次数已经使用完了")
    ---------------------------------------------------------------------
    for循环打印:
    #循环10次  range相当于变量的集合,一组数据 0-9

    #打印0,2,4,6,8 0,10,2
    #打印1,3,5,7,9 1,10,2
    for i in range(0, 10, 3) :
    print("loop", i)
    for i in range(10) :
    print("loop", i)

    for循环的嵌套:
    for i in range(4) :
    print("-------", i)
    for j in range(4) :
    print(j)
    if j > 1 :
    break
    ---------------------------------------------------------------------






  • 相关阅读:
    小码哥IOS大神班11期 大神班
    最近整理的一些前端面试题
    emm, flutter来了, 对比下 RN?
    爱Pia戏服务协议
    linux cent下redis安装、密码设置、开机启动服务
    mysqld 不定时挂掉,使用定时任务cron检测到挂掉后自动重启mysql
    《结对-结对编项目作业名称-需求分析》
    结对编程
    课堂作业第0周
    App Distribution Guide (二)
  • 原文地址:https://www.cnblogs.com/zhoutf/p/9087578.html
Copyright © 2020-2023  润新知