Note-python Basic Tutorial (Second Edition) chapter I

Source: Internet
Author: User

The first chapter of Rapid transformation: basic knowledge todivide and to

( Python3.0 Prior to 2.7 version)

>>> 1/2

==>0

evenly divisible, common division:

Solution 1:1.0/2.0 ==>0.5

Solution 2:from _future_ Import Division ==>0.5

mean divisible

>>>1//2

==>0

floating-point // floating-point number, the result is still evenly divisible

>>>1.0//2.0

==>0.0

Actual operation:

* * indicates a exponentiation

>>>-3**2

==>-9

>>> (-3) **2

==>9

The -3**2 is preceded by a minus sign, indicating that the precedence of the exponentiation is higher than the negation

To : Long integer

>>>10000000000000000

==>10000000000000000l

The number is too large to exceed the normal integer the scope of the representation, Python automatically converted to long integers. long integers and ordinary integers can be mixed.

Actual operation:

: Modules and cmath

>>>Import Math

>>>Math.floor (32.9)

==>32.0

a bit of a Java- guided package,Math.floor (32.9) converts floating-point 32.9 to integers.

>>>from math import sqrt

>>>sqrt (-1)

==> Value error:math Domain Error

The Math function cannot handle the square root of a negative number, and must use the cmath

>>>from cmath import sqrt

>>>sqrt (-1)

==>1j

Note: string str and repr

>>>Print repr (10000L)

==>10000l

>>>Print str (10000L)

==>10000

STR (): conversion to String type identification disappears

Repr(): Create a string (identical to the parameter)

": print string containing numbers ( string + number ) + ' number ', function with repr () Same

in:input and raw_input

Input(): What type of data are you knocking on ?

Raw_input (): No matter what the knock is, the string type "common"

Note-python Basic Tutorial (Second Edition) chapter I

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.