Some learn the basics of Python Note

1, input and output input-output

input () function when the input string is input.

Input format: variable = inut ( "prompt character")

eval () function can be converted into a digital string. Thus, eval () function is a very common function

      print output format control: print ( "enter here described {: .2f}". format (variable))

When the output string without formatting control, print ( "Output Format error")

comma print function becomes the result output space

2, python import standard library

        Python import using the import function in three ways to Example turtle

import turtle from turtle import setup or from turtle import * import (alias t is to call the library) turtle as t

In general, to make use of a third

3, to determine whether the elements in a list

Finally, in possible whether a character in an array inside

4 comments

Single-line comments: beginning with #

Multi-line comments: In '' 'three single quotes i.e., the beginning and end

5, the data type

String type single and double quotes is the same

List: an ordered sequence of zero or more data consisting of a list of the [], a comma-separated elements

6, the string

Index: A [m]

 

Slice: A [1: 3] means that the first, second character fetched character, but does not include the third character

7, for loop

Format: for variable in range (parameters)

loop statement

Count each cycle is variable

range () function generating cyclic count sequence:

The first format is: range (N), to generate a sequence of integers 0 to N-1, a total of N

The second format is: range (M, N), to generate a sequence of integers from N-1 to M, a total of NM

8, the basic data types

  1. Integer type: can be positive or negative, there is no limit of the range. pow (x, y): y-th power of x

  2. Float type: Inter uncertain mantissa floating-point operations, so that when the floating-point calculation, the round function is often used.

  3. round function Usage: round (x, d), the x-rounded, d is the decimal digits taken

  4. Scientific notation: 4.3e-3 represents 0.0043,9.6E5 represented 960000.0

  5. Complex type: z = a + bj, where, a is the real part, b is the imaginary part. z.real obtaining the real part, z.imag imaginary part is obtained

9, the value operator that

  1. x / y represents the x divided by y, and the significance of mathematics, like, generally produce float

  2. // y x denotes integer division, takes only the integer quotient of x and y

  3. % Remainder, modulo operation

  4. x ** y x to the power y denote

10, numerical computation function

  1. ABS (x) absolute value of x

  2. divmod (x, y) while the output quotient and remainder

  3. pow (x, y [, z]) power I, represents (x ** y)% z, z may be omitted, omit equivalent to 1 modulo

  4. round (x [, d]) rounded, d decimal digits are reserved, the default value is 0

  5. max (x1, x2, ...., xn) selecting the maximum value, the size is not limited to n

  6. min (x1, x2, ..., xn) for the minimum, not the size of n

11, casts function

  1. int (x) x fractional part is discarded and the integer becomes a

  2. a float (x) increases fractional part of the floating point number x

  3. Complex (x) changes in the imaginary part of the complex number x into

12, python logic operation

 

Published 37 original articles · won praise 17 · views 2589

Guess you like

Origin blog.csdn.net/qq_44384577/article/details/105294473