Learn Python Day01

Source: Internet
Author: User

What is Python

1. Object-oriented Interpretation line language

2. A very rich library

3. Indent using tabs as statements (white space)

Advantages:

  1. Free, open source

2. Scalability, embeddable

3. A very rich library

Disadvantages:

  1. Slow operating Speed

2. Less Chinese information

3. Code cannot be encrypted

Simple input and output:

Input: Name=input ("Please enter your name:")

  Output: Print ("Hello World")

  

Formatted output symbol:

%c converted to character (ASCII value, or string of length one)

%r takes precedence over string conversions with the repr () function

%s takes precedence over string conversion with the STR () function

%d/%i turns into signed decimal numbers

%u turns into unsigned decimal number

%o Turn unsigned octal number

%x%x to unsigned hexadecimal number (x/x/represents the case of the converted hexadecimal character)

%e/%e turns into scientific notation (e/e control output)

%f/%f to floating point number (small part stage)

Shorthand for%g/%g%e and%f/%e and%f

Percent output% (the formatted string includes a percent semicolon, then must be used)

\ n line-break output

"STR" *n output n times

Print ("No newline output:", end= "")

Variable:

Cases:

Name = "a" #不需要定义类型

Naming rules:

1. Only letters, numbers, and underscores can be included. You can start with a letter underscore, but you cannot start with a number.

2. You cannot include spaces, but you can use underscores to split them

3. You cannot use a keyword in python as a variable name

4. Suggested hump naming method to increase program readability

Key words:

Data type:

Int (integer)

Number float (floating point type)

Complex (plural)

BOOL (Boolean)

String (String)

List (lists)

Tuple (Ganso)

Sets (collection)

Dictionary (dictionary)

Type () #查看类型

Comments:

#

Single-line Comment

"""    """

Multi-line comments

Action string:

Intercept string Syntax:

Variable "start subscript: End Subscript"

The plus sign (+) is the connector for the string

An asterisk (*) indicates that the current string is copied

List:

list = [' abc ', 3, ' AAA ']

The list is written between square brackets, separated by commas

can be sliced and indexed as a string

You can use the plus sign (+) for stitching

The elements in the list can be changed.

Ganso

The Ganso is written in parentheses, and the elements are separated by commas.

Tuple1 = (' abc ', 1, ' AAA ')

Attention:

A tuple cannot be changed, but it can contain mutable objects. such as list lists

A ganso that constructs 0 or 1 elements has a special syntax rule:

tuple1= () #空元祖

Tuple2= (1,) #一个元素, you need to add a comma after the element

Dictionary:

A dictionary is a type of mapping, using {}, which is an unordered key (key) value pair set

Dict1 = {}

Dict2 = {' name ': ' Amanda ', ' age ': ' 10 '}

Attention:

A dictionary is a type of mapping

The key (key) must use the immutable type (string, numeric, Ganso), and the key must be unique in the same dictionary.

Create an empty dictionary with {}

Operator:

Plus (+), minus (-), multiply (*), except (/), take rest (%), power (*), and divide the portion of the returned quotient (//)

Logical operators:

and #布尔 "and"

or #布尔 "or"

Not #布尔 "non"

Bitwise operators:

A = 60

b = 13

  & #按位与运算符: Two values that participate in the operation, and if two corresponding bits are 1, the result of that bit is 1 a&b result 122 binary 00001100

  | #按位或运算符: As long as the corresponding two binary has one for 1 o'clock, the result bit is 1 a|b result 612 binary 00111101

  ^   #按位异或运算符: When two corresponding binary differences, the result is 1 a^b result 492 binary 00110001

  ~ #按位取反运算符: Reverse every bits of the data, turn 1 into 0, turn 0 into 1 ~a result-612 binary 11000011  

  << #左移动运算符: High Drop, low 0 a<<2 result 2,402 binary 11110000

  >> #右移动运算符: High 0, low discard a>>2 result 152 binary 111100 00

           

Learn Python Day01

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.