Python data type-----numbers & strings

Source: Internet
Author: User

Python number Type

The range represented by the int type is 2147483648 to 2147483648, and numbers beyond this range are treated as long (long shaping)

In Python, you do not need to declare data types beforehand, it is based on specific assignments for the counting data type, for example:

int type

Use the type (variable name) to see what the data type is after the variable is assigned

Numbers beyond the int range

The int type is stored as a long type

You just need to add capital letters to the back.

Plural types are also supported in Python

Plural type

Python String type

 #   Coding=utf-8  #   simple definition simple string  test1=  hello   " print   test1  #   defines a string containing single quotes  Test2= " i don ' t know  "  print   Test2  #   Defines a string that contains both single quotes and double quotes, escaping  test3= " i Don. t \ "know\"   " print  test3 

\ n line break

# Coding=utf-8 # simple definition simple string mail='totom:\n hello!\n I am jack! ' Print Mail

The above escapes are cumbersome to use, so you can use triple quotes (single quotes and double quotes).

# Coding=utf-8 # simple definition simple string mail="" ToTom:        hello!        I am jack! ' """ Print Mail
# Coding=utf-8 # simple definition simple string mail="toTom:        hello!        I am jack! ' " " Print Mail

Manipulating strings

Use variable name [string location number]

# Coding=utf-8 # simple definition simple string strval='abcd'print  strval[0]strval[1 ]print strval[1]

The above code prints out a value of a, b

# Coding=utf-8 # simple definition simple string strval='abcd'print strval[0]+strval[1]

Remove ' BCD ' from ' ABCD '

#Coding=utf-8#simple definition of simple stringStrval='ABCDE'#First KindPrintStrval[1:4]#value is BCD#The second KindPrintStrval[:4]#value is: ABCD#take negative indexPrintStrval[-1]#values are: EPrintStrval[-4:-1]#value is: BCD#reverse-Fetch valuePrintStrval[-2:-5:-1]#value is: DCB

Python data type-----numbers & strings

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.