zoukankan      html  css  js  c++  java
  • python基本语法

    1. 单行注释是#

      多行注释是'''    .....'''

    2.可以随心所欲定义变量

      name="dub

      age = 18

         tel = 18735122669

    3,变量

        整数

      浮点

      字符串 str

      布尔值

      None 相当于java中  ""

    4.运算符

      算数 + - * / %(模)    //(整)  **(幂)

      比较 >  <  <=  > =  ==   !=  <>(是否不相等)

      赋值= +-   -= /=   *= 

      成员 'a' in 'all'   a是否在all里  在为true    'a' not in 'all'  a不在 true

      身份

    5 引号

      单个用单引号   'a'

      多个用多引号 ''abc''

    6 元组

      a =(1,2,"abc'')

    7 列表 []

      a = [1,2,3,"abc"]

      a[1,3] 取下不取上 2,3

      a[-1] abc

    8 dictionary 字典  无序的

      dict = { "name":"dub","age":"18","sex":"boy"}

    9 遍历  

      for i (i是变量) in rang(1,10)

      for abc in a

    10.函数(严格区分缩进)          ** 代表多个参数

      def function(type 1,type 2....); 没有大括号

        可以return;

      def add(a,b=9) a位置参数,b 默认参数   ( 默认参数要放在位置参数后面)

    11,导入包 import

      from ... import...

    12.判断语句

      if ;

      elif ;

      else ;

    13 while

      while 判断条件;

      执行语句;

      条件体

    14. 流程控制

      break; 跳出循环

      contnue; 跳出本次  不打印

      pass ; 跳过本次继续打印

    15  输出格式 Io console

      Output()

      inPut()

      print("asfasdf" . fromat(str,str1));

    16.读写文件

      f = open('text.txt;,;w')

      f.write(text)

      f.close();

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

      f = open('text')

      while True;

        line = f.readline();

        if  len(line) == 0;

          break;

        print(line);

      f.close

    17 错误 异常

      错误代码运行不了

      异常 比如8/0  就会产生异常

      try;

        可能出现的异常

      except ValueErrr;

        print("...............'')

    18. self

      相当于this  super   ??

    19 对象的概念

    20.方法可以传入 方法当参数

      

      

  • 相关阅读:
    单元测试练习
    对软件的看法
    个人最终总结
    论文笔记--Fast RCNN
    个人最终总结2
    结对编程--基于android平台的黄金点游戏(2.0版本)
    结对编程--基于android平台的黄金点游戏
    团队作业(一)
    [java]wordcount程序
    第三周作业(二)
  • 原文地址:https://www.cnblogs.com/dubo-/p/8672320.html
Copyright © 2011-2022 走看看