python&int&method&string slices, indexes, lists, Ganso, dictionaries

Source: Internet
Author: User

I. Two methods of INT

A

__ADD__ ()

Bit_length ()

Number_one = 7
Number_two = 5
Print (Number_one + number_two)
Print (number_one.__add__ (number_two))
Print (Number_one.bit_length ())
Print (Number_two.bit_length ())

Effect:

12
12
3
3

Second, string index and slice

name = ' Jane '
Print (Name[0])
Print (name[1])
Print (Name[3])
Print (name[2])
Print (Name[0:4])

Effect:

J
A
E
N
Jane

Iii. list and some of his methods

A

Indexes and slices

Name_list = ["Jane", ' Jaymes ', ' Jackman ')
Print (name_list[0]) #索引
Print (Name_list[0:2])
Print (Name_list[0:len (name_list))) #切片

Effect:

Jane
[' Jane ', ' Jaymes ']
[' Jane ', ' Jaymes ', ' Jackman ']

B

Append ()

Effect: Add the rear of the butt

C

Count ()

Effect: View the number of occurrences of a member

D

Extend ()

Name_list = ["Jane", ' Jaymes ', ' Jackman ')
temp = [11, 22, 77]
Name_list.extend (temp)
Print (name_list)

Effect: [' Jane ', ' Jaymes ', ' Jackman ', 11, 22, 77]

E

Index ()

Name_list = [' Jane ', ' Jaymes ', ' Jackman ']
Print (Name_list.index (' Jane '))

Effects: Viewing the index in which an element appears

F

Insert ()

Effect: You can specify an index to insert an element

G

Pop () #可以指定索引, can also not be specified, do not specify from the bottom to start deleting

Del Name_list[i]

Effect: spare tire and puncture

H

Reverse () #列表反转

Sort () #排序

Remove ()

Iv. Ganso

A

Only count () and index () are supported

Five, dictionary

A

Favorite_languages = {

' Jane ': ' Python ',

' Jack ': ' C + + ',

' Rose ': ' PHP ',

' Jaymes ': ' Java ',

}

For I in Favorite_languages:

Print (i)#默认输出key

B

Key: Favorite_languages.keys ()

Value: Favorite_languages.values ()

K&v:favorite_languages.items ()

For K, V in Favorite_languages ():

Print (k, v)

C

Get () #通过get () Gets the value

Favorite_languages (' Jane ') #输出Python

Favorite_languages (' Jen ') #输出None

Favorite_languages (' Jen ', ' python ') output Python

D

Clear () #空字典了

E

ret = ' Jane ' in Favorite.keys ()

Print (ret)

F

Favorite_languages.pop (' Jane ')

Favorite_langugaes.popitem ()

G

Del favorite_languages[i]# puncture

H

Dictionary update () with extend ()

I

Favorite = [' Football ', ' iPhone ', ' cute ', ' MacBook Pro ']
For key, value in enumerate (favorite, 1):
Print (key, value)

ret = input (' Please enter your numbers: ')
Print (Favorite[int (ret)-1])

J

Add

PY 2.7

Range (0, $) #一下全部创建出来

Xrange (0, #只能通过for循环才能输出)

PY 3

Range (1, one) # can only be output with a for loop

Range (10, 0,-1)

Name_list = [' Jane ', ' Jen ', ' Lee ', ' Brouse ', ' Rudy ']

For I in range (0, Len (name_list)):
Print (i + 1, name_list[i])

python&int&method&string slices, indexes, lists, Ganso, dictionaries

Related Article

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.