Python Basic data type

Source: Internet
Author: User

The concatenation method of string

(a) direct use of "+" sign, low efficiency (will open up another space in memory)

name = ' Jacky ' + ' Zhao '

(ii) string formatting

Name = '%s%s '% (' Jacky ', ' Zhao ')

(iii) Join method

ListName = [' Jacky ', ' Zhao ']name = '. Join (ListName)

  

Two ways to create a list

#方式一a = [' A ', ' B ', ' 1 ', ' 2 '] #方式二a = List (' A ', ' B ', ' 1 ', ' 2 ')

List operation methods:

Indexed index

Slice:

Append Append

Length Len

Delete del, remove, pop

Loop for, while

(Interrupt loop) Break: Terminates the current loop

Continue: Terminating the secondary cycle

Pass: Placeholder (grammar check)

return: Function termination

Exit: Exit the program

Contains in, _contains_

Ganso's Modification:

Ganso elements are not modifiable

A = (1,2,3,4)

Del A[0]
Traceback (most recent):
File "<pyshell#38>", line 1, in <module>
Del A[0]
TypeError: ' Tuple ' object doesn ' t support item deletion

Elements of the Ganso element can be modified

A = (1,2,3,{' A ': ' B '}) (a[3][' a '] = ' C ') print (a) (1,2,3,{' A ': ' C '})

  

Python Basic data 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.