Python Learning 1, python Learning

Source: Internet
Author: User

Python Learning 1, python Learning

 

Download Python 3.6.3 from the official website ~

Enter the Python interaction environment ~

Hello World!

Input/Output ~

Python data type: integer, floating point number, String, Boolean value, empty, variable, constant

Integer, unlimited floating point size

Boolean: True, False (case sensitive)

| -- Escape Character

R'': ''is not escaped.

---- Makeup leakage -------------------------------------------

1 byte = 8 bits. The maximum integer for saving one word is 255.

ASCII encoding is 1 byte, while Unicode encoding is usually 2 bytes. If Unicode encoding is unified, garbled characters disappear. However, if all the text you write is in English, Unicode encoding requires twice as much storage space as ASCII encoding, which is not cost-effective in storage and transmission. In the spirit of saving, Unicode encoding is converted into a variable-length encoding.UTF-8Encoding. UTF-8 encoding encodes a Unicode character into 1-6 bytes according to different numbers, common English letters are encoded into 1 byte, Chinese characters are usually 3 bytes, only uncommon characters are encoded into 4-6 bytes. If the text you want to transfer contains a large number of English characters, using UTF-8 encoding can save space.

----- Makeup missed completion -------------------------------------

 

Returns the integer representation of a character.

Str in Unicode formatencode()The method can be encoded as the specifiedbytes

len()Function, computingstrNumber of characters

Since Python source code is also a text file, when your source code contains Chinese, when saving the source code, you need to specify to save as UTF-8 encoding. When the Python interpreter reads the source code, we usually write these two lines at the beginning of the file to make it read in UTF-8 encoding:

#!/usr/bin/env python3
#-*-Coding: UTF-8 -*-



In Python, the format is the same as that in C.%Implementation.

%Operators are used to format strings. Inside the string,%sString replacement,%dRepresents the number of Integers to replace.%?Placeholder, followed by several variables or values. The order must be consistent. If only one%?Brackets can be omitted.
To Format integers and floating-point numbers, you can also specify whether to add 0 or the digits of integers and decimals:


A built-in data type in Python is list: list. List is an ordered set that allows you to add and delete elements at any time.
Len (array name) -- number of array elements
Array name [-1] -- last element
Array name. append () -- add elements to the end
Array name. insert (1, 'xxx') -- insert xxx in array [1]
Array name. pop (I) -- delete a specified element without I
Array name [I] = 'xxx' -- replace element at I
Arrays can contain Arrays



Another ordered list is tuple. Tuple and list are very similar, but tuple cannot be modified once initialized. It does not have methods such as append () and insert. Other methods for retrieving elements are the same as those for listing.
Tuple is not defined, yes1This number! This is because of parentheses.()It can represent both tuple and parentheses in the mathematical formula, which leads to ambiguity.
Therefore, Python stipulates that, in this case, the calculation result is naturally1. Therefore, a comma must be added when only one tuple element is defined.,To eliminate ambiguity.
-- The list element in tuple is variable.



~~ Python stops on the first day and goes to bed ~~~

The course content is from Liao Xuefeng's official website. Thank you !!
 

 

 

 

 

 

 

 

 

 

 
 

 

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.