Python-based data types

Source: Internet
Author: User

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

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.