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)