The basic data types initial python

  1. variable

    • attach a label
    • Variable name rule: only letters and numbers underscore, can not start with a number, not the same name and keyword can not use Pinyin and Chinese, has descriptive, case-sensitive, variable names recommended wording: Hump mention, underscore (Official recommend)
    • Variable assignment
  2. constant

    • Features: fixed.
    • Writing specifications: all caps. (Python is not constant, agreed commonly known, is a constant variable name in uppercase)
  3. Note

    • Action: explanation, to facilitate understanding the code
    • Single-line comments: # + Notes content
    • Multi-line comments: "" "footnotes" '' and '' 'footnotes' ''
    • The content of the comment is not performed
  4. Basic data types acquaintance

    • String
      • str
      • For storing some data strings
      • It is due to the long string enclosed in quotation marks "" or "" or "" "" "." (Three quotes can also define the comment string, string comment when in fact that there is no assignment, the assignment also does not account for memory)
      • Can be added can multiply "jingjunke" + "keke" mosaic - "jing" * 5, five times the output
    • digital
      • int
      • For calculating, for comparison and determination, plus: +, decrease: -, by: *, except: /. % //
      • a = 10 - 2, at the time of assignment, perform a right hand side. Re-assignment
      • Division: python3 time division returns the decimal (floating point), ptrhon2 time division returns an integer (down)
    • Boolean value
      • bool
      • True: Ture, False: False
      • Logic, let the computer tell you or you tell the computer once judgment is true: Ture or false: False
    • List
    • Tuple
    • dictionary
    • set
  5. User interaction (input / output)

    • input ( "Please enter:")

    • Python3 data type is acquired in the input string (str type)

      python2 obtained is that the data itself

  6. type (): View data types

  7. Cast

    • int()
      • int () converts the data out. Rounding down
    • list()
  • tepul ()
    • ......
  1. Flow control statements

    • if conditions are: the election or do not choose

      money = 10
      print("从学校出发")
      if money>=10:
          print("买个炸鸡")
      print("走啊走。到家了")
    • if conditions:

    else condition: Choose one

    • if else else esle a multiple-choice or not vote
    • if elif elif elif else a multiple-choice
    • if if if if more than multiple-choice
    • if nested
  2. indentation

    • python omit the braces, with the distinction code blocks indented
    • tab

Guess you like

Origin www.cnblogs.com/jingjunke/p/11401592.html