Python data type

Source: Internet
Author: User

First, the number

1.INT (integer) is an integer, such as 5

Long integer 2.LONG (Long integer type)

3.FLOAT (floating-point) numbers with decimals

Use Type () to view variable types

Second, string

"Hello World"

1. Escape special characters with backslash (\)

>>> s = "Yes,he doesn\ ' t"
>>> Print (S,type (s), Len (s))
Yes,he doesn ' t <class ' str ' > 14

2. Add an R to the string to indicate the original string
>>> print (' C:\some\name ')
C:\some
Ame
>>> print (R ' C:\some\name ')
C:\some\name
>>>

3. Strings can be concatenated with the + operator string or repeated with the * operator:

>>> print (' str ' + ' ing ', ' my ')
String mymymy

4. Index

>>> a= "Hello World"
>>> print (a[0],a[3])
Hl

>>> print (a[-1],a[-3])
B 4

5. Slicing

>>> name = "Liyaoguo"
>>> Name[2:5]
' Yao '
>>> name[2:]
' Yaoguo '

6. String formatting

>>> name= "Liyaoguo"
>>> print ("I am%s"%name)

string%s; integer%d; floating-point number%f
I am Liyaoguo

7. Remove spaces

>>> name = "Yoyo". Strip ()
>>> Name
' Yoyo '

. Lstrip () Remove the left space,. Rstrip () Remove the space on the right,. Replace () to remove all spaces

Python data type

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.