zoukankan      html  css  js  c++  java
  • 管窥python语法

    刚接触python,mark下所见所得:

    1.Python调用底层API,可在任何platform上运行,包括Windows、Mac、Unix;

    2.用#符号对代码或语句进行注释,#后的代码不被编译;

    3.print的时候使用逗号[,]告诉解释器不作新行输出;

    4.python程序可以运行在windows shell里(cmd line);

    5.代码可以在notepad下编辑,纯文本结构文件;

    6.变量声明:v=2; v="can be changed to a string"; #the value of v can be changed at any time;

          name="paul cheng";同样用加号进行字符串连接;

    7.while循环:[代码逻辑结构完全用缩进控制,新鲜清洁]

        n=1

        while n<10:

          print n

          n=n+1

    8.function:

      1)definition:

        def hello():

          print "hello"

          return 1234

      2)invoke:

        "print hello()" will output result like: [after execution of print "hello", function returns 1234 for printing]

          hello

          1234

    9.Tuples, Lists, Dictionaries.

        1)Tuples: month = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun')

        2)Lists: cats = ['Tom', 'Snappy', 'Kitty', 'Jessie', 'Chester'] 

            add: cats.append("appendOne")

            delete: cats.remove("Tom") or del cats[n];

            get one: cats[1] will get "Snappy";

            get many: cats[0:2] will get "'Tom','Snappy','Kitty'";

        3)Dictinonaries: phonebook = {'paul cheung':123456, 'chirs paul':654321}

            add: phonebook['key']=value

            delete: del phonebook['key']

            keys: phonebook.keys() will return all keys as a list;

            values: phonebook.values() will return all values as a list;

    10.loop-for:

        for item in list:

          print item

    11.class:

        class person:  #definition

          def _init_(selef, name, age):  #.ctor

            self.name=name

            self.age=age

        class student(person):  #inheritence

          {statement...}

    12.module: #include variables/function/class;

    13.import module:

        import module_name

        from module_name import function_name/class_name

    14.use imported module:

        module_name.function_name/class;

        function_name if use from...import...

    15.file I/O:

        file = open('file_name', 'r/w')

        file.seek(int, int) #moving cursor

    16.error handling:

        try:

          {statement...}

        except NameError:

          {...}  #handle a type of error

        except SyntaxError:

          {...}  #handle another type of error

        or except (NameError, SyntaxError)

          {...}  #handle multilple types of error together

  • 相关阅读:
    03 Zabbix常用的术语
    01 Zabbix采集数据方式
    自学Zabbix13.1 分布式监控proxy介绍
    自学Zabbix12.5 Zabbix命令-zabbix_proxy
    自学Zabbix12.4 Zabbix命令-zabbix_sender
    自学Zabbix12.3 Zabbix命令-zabbix_agentd
    自学Zabbix12.2 Zabbix命令-zabbix_get
    自学Zabbix12.1 Zabbix命令-zabbix_server
    自学Zabbix11.6 Zabbix SNMP自定义OID
    自学Zabbix11.5 Zabbix SNMP监控实例
  • 原文地址:https://www.cnblogs.com/paul-cheung/p/3200420.html
Copyright © 2011-2022 走看看