Python Learning (2)--string and digital conversion __python

Source: Internet
Author: User

Convert string to number

Import string
ts = ' 123 '
num = string.atoi (TS)

int (x [, Base])         converts x to an integer     long (x [, Base])         convert x to a long integer     Float (x)               convert x to a floating-point number     complex (real [, Imag])   Create a complex number     STR (x)                 Convert object x to string     REPR (x)                 Convert object x to expression string     eval (str)               is used to compute a valid Python expression in a string and returns an object     tuple (s)           &NBSP ;   Convert sequence s to a tuple     list (s)                 to convert sequence s to a list of   &N Bsp Chr (x)                 Convert an integer to a character     UNICHR (x)               Convert an integer to Unicode character     ord (x)               &NBSP ; Converts a character to its integer value &nbsp   Hex (x)                 Convert an integer to a hexadecimal string     Oct (x)   &nbs P             Convert an integer to a octal string     
Convert numbers to Strings
num = 322
str = '%d '%num
#str即为num转换成的字符串
Commonly used formatting strings:
%d integer
%f floating-point numbers
%e Science Count

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.