Python Day01

Time:2019-9-8

Chapter I

Introduction to Python

  1. Python 2: Source code is inconsistent and duplicated (updated and maintained until 2020)

    Python 3: Unified source code, no duplication

    Python 2: Python 2 print is not used, print “content”

    Python 3: Print in Python 3 must be enclosed in parentheses, print (“content”)

    Python 2: Input in digital Python 2 yields int

    Input in Python 3: Python 3 yields str

    Python is a dynamic interpretative strong type definition language

II. Variables

  1. Variable naming rules

    • It consists of numbers, letters and underscores.

    • You can’t start with numbers.

    • Be descriptive

    • Case-sensitive

    • Prohibit the use of Python keywords

    • Cannot use Chinese characters or Pinyin (low)

    • Recommended Writing of Variables

      • Hump body

      • Underline (Official Recommendation)

3. Constants

Variables are all named in capitals, which are constants.

Notes

  1. Single-Line Comments

    • It’s also called line commentary with #.

    • Comments for the current line

  2. multiline comment

    “””

    “””

    Three quotation marks, document annotations, and annotations describing the use of files or functions

V. Basic Data Types

  1. String str

    • “String asdasdasdada”

      • STR + str (string splicing)

      • STR * int (splicing strings multiple ints)

  2. Plastic (digital) int

    • Used for comparison and calculation

      Python 2: When dividing, it returns an integer (take the integer down)

      Python 3: The decimal (floating point) returned by Division

  3. Boolean bool

    • Used for judgment

      • True – True

      • False – False

VI. User Interaction

  1. Input — Input: Input in Python 3 gets strings

  2. Print — Output

    number = input("Please enter your content:")
    print(number)

7. Viewing Data Types

  1. type

    • View data types

      • Int (str) – Converting strings into integers

      • STR (int) – Converting integers to strings

    Type (object to be detected)

8. Process Control Statements

  1. Single if

    • If condition:

      Indentation result

      money = 10
      print("Starting from School")
      if money >= 10:
         print("Buy a fried chicken")
         print("Buy a beer")
      print("Walk, walk")
      print("Home")
  2. Two choices, if else

    • If condition:

      Indentation result

      else:

      Indentation result y

      if 3>2:
         print("If this is done")
      else:
         print("This is otherwise implemented")
  3. Choose one more or no if elif elif elif

    • If condition:

      Indentation result

      Elif condition:

      Indentation result

      Elif condition:

      Indentation result

      if 1>2:
         print("This is A")
      elif 1>6:
         print("This is B")
      elif 1>5:
         print("This is C")
      elif 1>4:
         print("This is D")# No output without meeting the requirements
  4. Choose one more if elif elif else

    • If condition:

      Indentation result

      Elif condition:

      Indentation result

      Elif condition:

      Indentation result

      else :

      Indentation result

      if 1>2:
         print("A")
      elif 2>3:
         print("B")
      elif 5>6:
         print("c")
      else:
         print("D")
  5. If nesting

    • If condition:

      Indentation result

      If condition:

      Indentation result

    score
    if score > 500:
       if score > 700 :
           print("Tsinghua University of Peking University")
       else:
           print("Find a university at will")
    else:
       print("Not enough points to go to college")

Recommended Today

Resolving Time Zone Errors with Docker

1. The correct time zone in China is set to CST, i.e.China Standard TimeIn usedockerstart-upJenkinsWhen mirroring, the settings for mirroring are usuallyCoordinated Universal Time。 So add parameters at startup -v /etc/localtime:/etc/localtimeMount the local time zone to the mirror, so that the mirror gets the correct time zone. Then go to Jenkins and fill in the […]