Python learns Day2 (some small magic of strings)

Source: Internet
Author: User

1.Join(concatenation of the string according to the specified stitching character)

1 s = input (" Please enter string:")2'_'. Join (s)3print(S1)

The meaning of this code is to underline the input string.

#利用下划线将列表中的每一个元素连接成字符串 #
L = ['John','Paul','durant' '_'. Join (L)print(L1)

These short lines of code connect each element of the L list with an underscore. only strings in the list can be spliced by the Join method

The join usage in this meaning is to add the same insertion after each element in the original string.

#how many decimal decimals and letters are there in the string that calculates user input? #s= Input ("Please enter a string:") Count1=0count2=0 forIinchS:ifI.isdecimal () isTrue:#Decimal is only available for decimals, digit and numeric are more versatile #Count1 + = 1ifI.isalpha () isTrue:#determine if the traversed string is a letter #Count2 + = 1Print(Count1,count2)

Python learns Day2 (some small magic of strings)

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.