Python Learning notes section fourth (character encoding + text manipulation + functions)

Source: Internet
Author: User

The meaning of a constant does not exist in Python
You can only use uppercase names to indicate that this assignment is a constant, which is actually a variable

Character encoding

In-memory is Unicode
The hard drive is utf-8.
Middle need to convert

Python has the concept of character encoding only when it executes
Python2 default ASCII code
Python3 default Unicode

File operations

Write operation, W does not have a new overwrite, A is append

Name view file name
Encoding viewing character encodings

To see if it is readable
To see if it is writable true false

Display as file characters

Seek to move the cursor position to the beginning of the file to read, Byte, in 0 Utf-8 three characters is a Chinese character

Print the current cursor position

Backwards seek.

Truncation, leaving only 3 bytes, the rest is deleted, this is a write operation, must be with the W parameter

Three additional parameters, mode

Open in Byts format

Decoding in UTF-8 format

Open the binary of the picture

Copy a picture in a binary way

Write absolute path in Windows requires 2 \ \ or the front price is small r

Looping through text

Optimization

Function

To find the maximum value
Minimum value
Sum

Add parameters to the function (number of stars, number of rows)

Defining an parameterless function
You can write the command you call to a function 1

return value
The return value can only be returned once but can be written more than once, returning once after the function ends

The return value of the function is calculated

Python Learning notes section fourth (character encoding + text manipulation + functions)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.