python22期自动化-Day1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python22期自动化-Day1相关的知识,希望对你有一定的参考价值。

为什么要编程:

为了解决生活中的问题

编程语言:

C
C#
Java
PHP
Ruby
Python
...

分类:
    C和其他:
        C       编译为机器码
        其他  编译为字节码

难易程度:
    C
    C#/Java
    PHP
    Python(类库齐全)

python编译器(将代码编译成字节码,C再将字节码编译成计算机识别的机器码(2进制)):

version:
    python2(主要python2.7)
    python3(主要python3.6)
type:
    CPython(编译器为C)
    JPython(编译器为Java)
    RubyPython(编译器为Ruby)
    PyPy(编译器为python)
    目前我们广泛使用的python为CPython

编译型和解释型:

编译型:全部写完之后,再统一编译(C、C#、Java)
解释型:即时翻译(Python、PHP)

编码(类似于密码本):

Acsii       欧美使用,1字节,8位
Unicode     万国码,4字节,32位,太大不利于写入磁盘
utf-8       至少1字节(8位),写入磁盘编码,中文占3字节 *****广泛使用
gbk         亚洲使用,中文占2字节

输入和输出:

input(输入):
    import getpass  # 密文输入,pycharm不能运行,只能在终端运行
    username = input(‘please input username: ‘)
    password = getpass.getpass(‘please input password: ‘)
print(输出);
    print(username)
    print(password)

raw_input(python2中的输入):
    username = raw_input(‘please input username: ‘)

变量:

1、只能包含数字、字母、下划线
2、数字不能开头
3、不能使用python内置关键字
建议:见名知意,小写,下划线分割

条件语句:

if 条件:
    条件为真则执行
else:
    条件为假则执行

if 条件1:
    条件1为真则执行
elif 条件2:
    条件2位真则执行
else:
    所有条件都不为真则执行

username = input(‘please input username: ‘)
password = input(‘please input password: ‘)

if username == ‘wanliang‘ and password == ‘123456‘:
    print(‘login success‘)
else:
    print(‘login fail‘)

# if语句嵌套
    msg = ‘‘‘
            1、查询话费
            2、查水表
            3、人工服务
            ‘‘‘

    print(str(msg))

    choice = input(‘please input choice: ‘)

    if choice == ‘1‘:
        print(‘1、查询本机;2、查询他人手机;3、查询座机‘)
        search = input(‘please input search: ‘)
        if search == ‘1‘:
            print(‘查询本机‘)
        elif search == ‘2‘:
            print(‘查询他人手机‘)
        elif search == ‘3‘:
            print(‘查询座机‘)
        else:
            print(‘查询类型输入错误‘)
    elif choice == ‘2‘:
        print(‘查水表‘)
    elif choice == ‘3‘:
        print(‘人工服务‘)
    else:
        print(‘输入错误‘)

循环语句:

while死循环:
    while 条件:
        如果条件为真则执行

    每循环一次就检查一次条件是否为真,不为真则结束循环*****

    count = 1
    while count < 11:
        print(count)
        count += 1

    count = 1
    while True:
        print(count)
        if count == 10:
            break
        count += 1

    count = 1
    while True:
        if count == 7:
            pass
        elif count == 11:
            break
        else:
            print(count)
        count += 1  

break       终止当前循环
continue    跳出当次循环,执行下次循环

数据类型:

1、int(整型)       18
2、str(str)      ‘i am str‘
3、list(列表)      [‘a‘, ‘b‘, ‘c‘] 以,分割,共有三个元素
4、dict(字典)      {‘name‘: ‘wanliang‘, ‘age‘: ‘18‘} 以,分割,共有两个元素(键值对)

数据类型嵌套:
    列表或字典内可嵌套多种不同的数据类型,如:
        [‘a‘, 1, {‘name‘: ‘wanliang‘}, [11,22]]
        {‘name‘: [‘alex‘, ‘eric‘], ‘age‘: 18, ‘passwd‘: ‘teacher‘}

通过索引切割数据, 如:
    1、str_type = ‘alex‘
    str_type[2] ---> e

    2、list_type = [1, 2, 3, 4]
    list_type[3] ---> 4

    3、list_type = [1, ‘wanliang‘, {‘name‘: ‘alex‘, ‘age‘: 18}]
    alex ---> list_type[2][‘name‘]      # 字典的元素是“键值对”,通过键取值
    18 ---> list_type[2][‘age‘]

以上是关于python22期自动化-Day1的主要内容,如果未能解决你的问题,请参考以下文章

Python 自动化入门 day1复习

Python自动化开发,Day1 - Python基础1

第9期《python3接口自动化测试》课程,6月29号开学!

Python自动化-Day1

python自动化运维之路~DAY1

Python自动化课之Day1篇 (未完)