Python beginner day1--(basic data types and common methods in Python)

Source: Internet
Author: User

Basic data types and common methods in Python

Common data types in Python are: string (str), list, tuple (tuple), dictionary (DITC), collection (set)

(a) string

Common methods of strings:

1, index, the character of the corresponding position is output by subscript.

eg:i = ' Hello World '

Print (i[3]) Result: ' L '

2, Length (len), gets the length of a string.

eg:i = ' Hello '

Print (len (i)) Results: 5

3, remove whitespace (strip), remove whitespace (spaces) on both sides of the string.

eg:i = ' Hello '

new_i = I.strip ()

Print (new_i) results: Hello

4, Split (split), divides a string into two parts.

eg:i = ' HelloWorld '

new_i = I.split (' ll ')

Print (new_i) Result: [' he ', ' Oworld ']

5, slices, gets a part of the string.

i = ' HelloWorld '

Print (I[1:5]) Result: ' Ello '

It is important to note that the subscript in Python starts at 0.

(ii) List

List of commonly used methods:

1, index 2, Slice 3, append 4, delete 5, length 6, loop 7, inclusive

(iii) tuples

1, index 2, slice 3, length 4, loop 5, including

(d) Dictionaries

1, index 2, add 3, delete 4, length 5, loop

(v) Collection

1, add 2, delete 3, length 4, loop

Python beginner day1--(basic data types and common methods in Python)

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.