Set Sail Python(3)

variable

  • Also known as theidentifierContains letters, digits, and underscores (_)
    • You can’t start with a number
    • Case sensitive
  • Meaning at the beginning of the underline
    • Single-underscore: Indicates class attributes that cannot be accessed directly
    • Double underscore: Represents the private member of the class
    • Double underscore beginning and end: Class constructors, special method identification
  • delTo delete a variable

Reserved words

  • Cannot be used as a variable name or other identifier name
and exec not
assert finally or
break for pass
class from print
continue global raise
def if return
del import try
elif in while
else is with
except lambda yield

Module partition

  • To write modules with indentation, all code block statements must contain the same amount of indent whitespace
  • Blank lines are used to separate the beginning of a new code and separate two pieces of code with different functions or meanings for future code maintenance or reconstruction

Variable types

  • Numbersdigital
    • int(Signed integer)
    • long(long integer [can also represent octal and hexadecimal numbers])
      • Python uses L to display long integers
      • Python2. X support
      • Python3.X, removed data type, used int instead
    • float(Floating point)
    • complex(plural)
  • Stringstring
    • Order of values
      • Indexing from left to right starts at 0 by default, and the maximum range is 1 less in string length
      • Indexing from right to left starts at -1 by default and the maximum range is at the beginning of the string
    • Intercept string[Head subscript: tail subscript: step size]
    • Operation symbols
      • +Is a string concatenation operator
      • *Is a repeat operation
  • ListThe list of
    • [Element 1, element 2...]
      • Data structures for most collection classes
      • Support for characters, numbers, strings and even lists
    • Values are in the same order as strings
    • Interception operation, same as string
    • Update the data
      • List name [subscript] = value
  • Tupletuples
    • (Element 1, element 2...)
      • Cannot be assigned twice, equivalent to a read-only list
  • DictionaryThe dictionary