zoukankan      html  css  js  c++  java
  • python笔记02

    day02笔记记录

    一、今日摘要

    循环、字符串格式化、运算符、编码、博客。

    二、内容回顾

    (一)计算机基础

    计算机由硬件和软件组成。传统计算机的硬件一般有输入单元、输出单元,算数逻辑单元、控制单元及记忆单元,其中算术逻辑单元和控制单元合称为中央处理器(CPU)。

    (二)安装解释器

    py2和py3安装。

    (三)语法:print/input:

    (1)python2和python3的输入:

    Python2的输入:

    input():只支持正确的数值类型,不接受字符串输入。

    raw_input():可接受数值和字符串,输出的类型均为字符型。

    Python3的输入:

    input():可接受数值和字符串,输出类型均为字符型。

    (2)python2和python3的输出:(py2不需要括号,py3需要括号)

    python2的输出:

    print“你好”

    python3的输出:

    print(“你好”)

    (四)字符类型

    整形int。

    字符串str。

    布尔值boolen。

    (五)条件语句结构

    if  条件:
    print(‘输出!’)
    elif 条件:
    print(‘输出!’)
    else:
    print(‘输出!’)
    

    (六)编码类型:

    assic(1字节);

    unicode(4字节);

    utf-8(1-3字节);

    gbk;

    bgk2312;

    (七)练习,评分规则:

    score=input('请输入你的成绩:')
    score=int(score)
    if score > 90:
        print('you get :A')
    elif score > 80:
        print('you get :B')
    elif score > 70:
        print('you get :C')
    else:
        print('you get :D')
    
    

    (八)10086练习

    message='''欢迎致电100086:
    1、话费查询;
    2、流量服务;
    3、业务办理;
    4、人工服务;
    '''
    print(message)
    
    index=input('请输入你要服务号码:')
    index=int(index)
    
    if index==1:
        print('话费查询')
    elif index ==2:
        print('流量服务')
    elif index==3:
        content='''业务办理:
        1、修改密码;
        2、更改套餐;
        3、停机;
        '''
        print(content)
        vlaue=input('请输入业务办理号码:')
        vlaue=int(vlaue)
        if vlaue==1:
            print('修改密码')
        elif vlaue==2:
            print('更改套餐')
        elif vlaue==3:
            print('停机')
        else:
            print('输入错误,请重新输入')
    elif index==4:
        print('人工服务')
    else:
        print('输入错误,请重新输入')
    
    

    三、循环

    while 的循环结构为:while else

    (一) 请打印1,2,3,4,5,6,7,9,10

    方法1:
    count = 1
    while count <= 10:
        if count == 8:
            pass
        else:
            print(count)
        count += 1
    方法2:
    conut=1
    while conut <=10:
        if conut !=8:
            print(conut)
        conut+=1
    方法3:
    count = 1
    while count < 8:
        print(count)
        count += 1
    count =9
    while count <= 10:
        print(count)
        count+=1
    方法4:
    count=1
    while count<=10:
        if count ==8 :
            count+=1
            continue
        else:
            print(count)
            count+=1
    

    条件是false时候执行else,break后不执行本while循环,continue后跳出本次循环,继续循环下次循环。
    while 基本结构:while else
    break
    continue
    while else

    四、字符串格式化

    (一) 占位符格式化

    例子1:

    name=input('姓名:')
    do = input('在干什么:')
    template = '%s 在教室,%s' %(name, do,)
    print(template)
    
    

    例子2:

    template="我是%s,年龄%s,职业%s。" %("alex",73,'讲课',)
    print(template)
    

    占位符%s表示:字符串;

    占位符%d表示:数字。

    如果想打印出第二个%,需要在第二个%前再加一个%。

    name=input('请输入姓名:')
    template="%s现在手机的电量是100%%"%(name,)
    print(template)
    

    例子3:

    name = input('your name is :')
    age = input('your name is :')
    job = input('your job is :')
    hobby = input('your hobby is :')
    msg = '''
    -----------info of alex----------
    name=%s
    age=%s
    job=%s
    hobbie=%s
    ------------end-----------------'''
    
    data = msg % (name, age, job, hobby,)
    print(data)
    
    

    五、运算符

    (一)运算符介绍

    ①%:取余数
    ②/:除法
    ③//:除法取整

    例子:取奇数:

    count=1
    while count<=101:
        if count%2==1:
            print(count)
        count+=1
    
    

    例子:计算1-100之和:

    count=0
    total=0
    while count<=101:
        total=total+count
        count+=1
    print(total)
    
    

    (二)运算符高级应用:

    比较和赋值运算

    =
    +=
    *=
    /=
    %=
    **=
    //=
    

    (三)逻辑运算:

    and
    or
    not
    

    (1)or运算

    ①value=1 or 9

    value=1
    ②value=0or9

    value=9
    ③value=0or''

    value=''

    总结:x or y---if x is false ,then y,else x
    如果有多个or条件,从左到右依次进行上述流程。

    (2)and运算:

    ①v1=1 and 9

    v1=9
    ②v1=1 and 0

    v1=0
    ③v1=0 and 7

    v1=0
    ④v1=0 and ''

    v1=0

    总结:x and y--if x is false,then x,else y

    如果有多个and条件,从做到右依次进行上述流程。

    (3)布尔运算

    数字转布尔值:

    ①false:0、空字符串,None。

    ②其他都是true。

    ③布尔值转换成数字,只有0和1。
    ④布尔值转换成字符串,只有False和True

    (4)not运算:

    if x is false,then true,else false。
    综合or,and:
    v1=1 and 9 or and 6

    v1=9
    优先级:先计算and,再算or

    六 、编码复习

    (一)编码类型

    ascii:1字节,8位,py2默认编码。
    unicode:4字节,32位。

    ecs2,2个字节
    ecs4,4个字节
    utf-8:1至3字节,(中文标示3个字节)。
    utf-16,
    gbk:(中文用2个字节)
    gb2312:(中文用2个字节)

    (二)单位:

    8bit=1byte
    1024byte=1kB

    七、博客园基本使用

    (一)博客文各属性介绍

    ①随笔:可以随便看

    ②文章:别人看不到,需要url才能看

    ③日记:只能自己看

    (二)git版本管理工具

    下载、安装、码云注册(保存代码)、创建仓库(创建文件夹)、写作业并提交。

    (1)如何提交作业

    在某个作业文件夹下作业

    在文件夹上右键:
    gitbase

    在黑框里:git init,

    用于git将当前文件夹管理起来
    git add .

    将当前文件夹的所有文件收集起来。

    git commit -m “第二天的作业”,做个记录。

    第一次时候需要:
    git config --global user.name"崔永超"

    git config --global user.email "cuiyongchao007@163.com"

    git remote add origin https://gitee.com/cuiyongchao007/

    项目名称
    上传:
    git push origin master

  • 相关阅读:
    Linux系统中压缩与解压缩
    Linux系统中的信息查找命令
    Paraview处理fluent计算结果
    insert_stream 中的 insert_every报错
    LIGGGHTS出现错误提示ERROR: Volume expectancy too small
    影响CFD计算量的因素分析及在OpenFOAM中的参数调整
    常见物理量的单位在OpenFOAM中的形式
    LIGGGHTS运行命令
    汇编系列10-内存
    汇编系列9-通用寄存器
  • 原文地址:https://www.cnblogs.com/cuiyongchao007/p/12037065.html
Copyright © 2011-2022 走看看