1. Data type
Data types in Python
Python uses the object model to store data, each of which has a built-in class, and each new data is actually initialized to generate an object, that is, all the data is objects.
2. String
2.1 Definitions
Definition: It is a collection of ordered characters used to store and represent basic textual information, "' or" "or" ' "" that contains what is called a string
Characteristics:
1. Only one value can be stored
2. Non-volatile
3. Define the character set in left-to-right order, the subscript is accessed sequentially from 0, ordered
2.2 String Common operations
msg= ' Hello '
Remove whitespace Msg.strip ()
Split Msg.split (' | ')
length Len (msg)
Index MSG[3] Msg[-1]
slices Msg[0:5:2] #0 2 4
Character Factory function str ()
#首字母大写
# x= ' Hello '
# Print (X.capitalize ())
#首字母大写
# x= ' Hello '
# Print (X.title ())
#所有字母大写
# x= ' Hello '
# Print (X.upper ())
# Center Display
# x= ' Hello '
# Print (X.center (30, ' # '))
#统计某个字符的出现的次数, spaces are also counted as characters
# x= ' Hel lo Love '
# Print (X.count (' l '))
# Print (X.count (' l ', 0,4)) # 0 1 2 3
# x= ' Hello '
# Print (X.endswith (")) # Take the next few characters of X
# Print (X.startswith ()) # Take the first few characters of X
#查看字符中单字符的位置
# x= ' Hello '
# Print (X.find (' e '))
# Print (X.find (' l '))
#格式化字符串
# msg= ' name:{},age:{},sex:{} '
# Print (msg) #Name: {},age:{},sex:{}
# Print (Msg.format (' Egon ', ' Male '))
Python-based data types