Python Learning manual Note (1): Python object type

Source: Internet
Author: User

In Python all objects, Python programs can be decomposed into modules, statements, expressions and objects. As shown below:

1 program consists of modules

2 module contains statements

3 statement contains an expression

4 expression creation and processing of an object


Built-in objects (core types):

1) Number:

>>> #整数加法

4

>>> 1.5*4 #浮点数乘法

6.0

>>> 2**10 #2的10次方

1024


2) String:

>>> s= ' ABCDEFG '

>>> Len (s) #len函数验证变量的长度

7

>>> S[0] #获取某个元素

A

>>> S[1]

' B '

>>> S[-1] #反向索引

' G '

>>> S[len (s)-3]

E

>>> s[1:] #分片

' BCDEFG '

>>> s

' ABCDEFG '

>>> S[:3]

' ABC '

>>> S[:-1]

' ABCdef '

>>> s+ ' xyz ' #字符串合并

' Abcdefgxyz '

>>> s= ' F ' +s[3:] #建立一个新的字符串 and named with the same variable name to change its assignment

>>> s

' FDEFG '


3) List

>>> l=[123, ' spam ', 1.23]

>>> L

[123, ' spam ', 1.23]

>>> L[0] #显示列表一个元素

123

>>> L + [4,5,6]

[123, ' spam ', 1.23, 4, 5, 6]


>>> m=[[1,2,3], #嵌套

... [4,5,6],

... [7,8,9]]

>>> M

[[1, 2, 3], [4, 5, 6], [7, 8, 9]]

>>> M[0] #显示第一行

[1, 2, 3]

>>> M[0][2] #显示第一行中的第3个元素

3

Not to be continued ...

This article from "10,000 years too long, seize" blog, please be sure to keep this source http://zengwj1949.blog.51cto.com/10747365/1928404

Python Learning manual Note (1): Python object 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.