Python-fullstack-s13-day02-python Foundation

Source: Internet
Author: User
Tags coding standards

First, the format of the output

1. Format the output by%

The formatted output is to output a string in a fixed format, as it involves external input or the output of a template that needs to be used by a certain demand, resulting in the need to occupy some of the output content using%.

The existing formatted output mainly learns%s and%d.

1Name = input ("Please enter your first name:")2age = Int (input ("Please enter your age:"))3Job = input ("Please enter your work:")4Hobby = input ("Please enter your hobby:")5 Print("""------------Info of%s-----------6 Name:%s7 Age :%d8 Job:%s9 Hobbie:%sTen -------------End-----------------"""% (Name,name,age,job,hobby))

Sometimes if your string is in the form of%s or%d, the trailing% is considered a placeholder, and if you need to use%, you need to write a percent, which means you are escaping.

1 Print (" My name is%s, I have completed 2% of my lessons in Python.") ")

If the placeholder does not appear in the string, then your% is still your% and nothing has changed.

1 Print (" My name is Alvarez, I have completed 2% of my lessons in Python. ")
second, the basic operator.

Operator

Computer can be carried out many kinds of operations, can not only subtraction so simple, operations by type can be divided into arithmetic operations, comparison operations, logical operations, assignment operations, member operations, identity operations, bit operations, today we only learn arithmetic operations, comparison operations, logical operations, assignment operations

Arithmetic operations

The following hypothetical variables: a=10,b=20

Comparison operation

The following hypothetical variables: a=10,b=20

Assignment operations

The following hypothetical variables: a=10,b=20

Logical operations

Further research for logical operations:

1, in the absence of () the not priority is higher than and,and priority above or, that is, the priority relationship is () >not>and>or, the same priority is computed from left to right.

Examples:

Determine the true,false of the following logical statements.

3>4 or 4<3 and 1==11 < 2 and 3 < 4 or 1>2 2 > 1 and 3 < 4 or 4 > 5 and 2 < one > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < Bayi > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
7 < 6

2, x or Y, X is true, the value is X,x is False, the value is y;

X and Y, X is true, the value is y,x false, and the value is x.

 

Example: Find the values of the following logical statements.

8 or 4 and 3 or 7 or 9 and 6

In,not in:

Determines whether the child element is in the original string (dictionary, List, collection):

For example:

#print (' Like ' in ' dkfljadklf like Hfjdkas ') #print (' A ' in ' Bcvd ') #print (' Y ' isn't in ' Ofkjdslaf ')
Third, the Code

Coding is a very important work, perhaps the current learning may not be so important, but involves the network transmission, front-end and other content needs to have a detailed understanding of the coding, today first to understand the code.

When the first computer was created by the United States ASCII code, ASCII code can not be installed in Chinese, 8 bit composition, up to 256 possible, the United States used 0-127, the remaining for expansion;

Since 128 extensions are left in the US ASCII code, compared to countries like China, 128 cannot fully represent Chinese characters, so China has designed GBK,GBK support for Chinese, 16bit =>2byte on the basis of ASCII. But this extension cannot be used universally in the world, and it may be possible to use a file in China, but it is not necessarily universal in other places.

In order to solve the same coding standards across countries, the extension of Unicode, referred to as the universal code, the purpose is to encode all the languages of all countries, accounting for 32 bits. But its disadvantage is waste. The contents of the ASCII code can not be changed, the encoding should also be the original encoding, but Unicode occupies 32 locations, ASCII will force in front of 24 0. Space is wasted on network transmissions and data storage.

To solve the problem of Unicode wasting, there is a variable-length Unicode encoding, called utf-8,8, that means a minimum of 8 bits of a character.

English: 8bit 2byte

Europe: 16bit 2byte

English: 24bit 3byte

Computer Storage System Unit conversions
8bit = 1byte
1024byte = 1KB
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB

Python-fullstack-s13-day02-python Base

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.