西维蜀黍

【Engineering】Encode

ASCII is a simple form of Unicode text, but just one of many possible encodings and alphabets. Text from non-English-speaking sources may use very different letters, and may be encoded very differently when stored in files.

ASCII

ASCII, abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Most modern character-encoding schemes are based on ASCII, although they support many additional characters.

  ...


【Python】Basics - Simple Data Types - String

String

  • Strings in Python can be enclosed in either single quotes (’) or double quotes ("), or three of each (’’’ or “”")
  • Double quoted strings can contain single quotes inside them, as in "Bruce's beard"
  • and single quoted strings can have double quotes inside them, as in 'The knights who say "Ni!"'
  • triple quoted strings: strings enclosed with three occurrences of either quote symbol (either single or double quotes)

  • can even span multiple lines

  ...


【Python】Basics - Variables

Assignment statement

Assignment statement gives a value to a variable:

  • assignment token: =
  • equals: ==

Ask the interpreter to evaluate a variable

  ...


【Python】Basics - Exceptions

Using try-except Blocks

When you think an error may occur, you can write a try- except block to handle the exception that might be raised. You tell Python to try running some code, and you tell it what to do if the code results in a particular kind of exception.

Here’s what a try- except block for handling the ZeroDivisionError exception looks like:

try:
		print(5/0) 
except ZeroDivisionError:
		print("You can't divide by zero!")
  ...


【Python】IO - WriteFiles

Writing to an Empty File

To write text to a file, you need to call open() with a second argument telling Python that you want to write to the file. To see how this works, let’s write a simple message and store it in a file instead of printing it to the screen:

filename = 'programming.txt'

with open(filename, 'w') as file_object:
		file_object.write("I love programming.")

The second argument, ‘w’, tells Python that we want to open the file in write mode. You can open a file in read mode (‘r’), write mode (‘w’), append mode (‘a’), or a mode that allows you to read and write to the file (‘r+’). If you omit the mode argument, Python opens the file in read-only mode by default.

  ...