Python Learning Week1

Source: Internet
Author: User

What kind of language is 1.Python?

Python is a very advanced language, and it contains a very rich library. Using Python can greatly improve the productivity of a programmer, because to complete a project, you do not need to start from the "wheel".

Python is an interpreted language, unlike a compiled language, such as C + +. A compiled language is an executable file that is converted to a machine-code representation of all code in a compiled environment. This is the process of translating all of the first and then the operation. And, interpreted language, is to explain a sentence to run, while explaining the way the side runs. Compiled language because the executable file of the. exe is rendered, the user who gets the file cannot reverse its code, so the confidentiality is strong. Explanatory language is open source, the code does not have a little protection, so confidentiality is poor.

Python is the language of a dynamic variable, as opposed to a static variable. Static variables are defined before the use of variables, and when a variable defines a data type, it can only accept data of that data type, such as int can only accept integers, and string can only accept character types. But dynamic variable language does not have so many constraints, the variables need not be defined before use, the same variable can accept different types of data.

2. Character encoding and Binary

At the bottom of the computer, the 01 code is represented by the on-off circuit. A byte of eight bits with a binary can represent the number of decimal 0-255. The Western world used 0-127 to denote its characters commonly used, which includes 26 of the English alphabet, which is the famous ASCII table.

However, the remaining 128 digits in the ASCII table cannot represent characters commonly used in the Chinese world. So the Chinese extended the ASCII table, so there was GB2312, which stored about 7,000 characters. But later found that 7,000 characters far from satisfying the demand, so the Chinese further expanded to GBK1.0, and then later GB180380, these tables have about 20,000 characters.

The ASCII character encoding table is extended in China, and people from other countries are expanding. International calls for a unified code table, encompassing all the characters of the country, so Unincode came into being. But Unicode stores all of the symbols are unified space, even for the English characters are the same, which creates a large space-occupying, redundant problems. So, later UTF-8 was born, this is a variable long character encoding method. UTF-8 applications are very extensive.

3. Three ways to format strings

Way one: Connect strings with the most primitive +

info= '----------info of ' + name + '-------

Name: "+ name +"

Age: ' +age + '

Print (Info)

Mode two: Formatting with placeholders

info= '----------info of ' '%s--------

name:%s

age:%s

job:%s

salary:%s

"% (name,name,age,job,salary)

Method Three: Through format representation, clearer and more clear

info= '----------info of ' ' {_name}--------

Name:{_name}

Age:{_age}

Job:{_job}

Salary:{_salary}

". Format (_name=name,

_age=age,

_job=job,

_salary=salary)

Note: the input () statement gets the data type is a string

4. Judging structure and cyclic structure in the sequential structure

1. Judging the structure, namely:

If Condition One:

Statement One

Else

Statement Two

Note: If and else are at the same level. Before statement one and statement two, there are 4 spaces or tab keys.

2. There are two types of looping structures: for And while

For x in []:

Statement One

That is, each element in list[] participates in the operation of statement one in X.

While condition one:

Statement One

When the condition is established, the statement one is executed until the condition is not established.

3. Special statements: Break and Continue

Break statement function: Exits the loop and does not perform the subsequent loop.

Continue statement function: Exits the current loop and also executes the following loop.

Python Learning Week1

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.