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