The path to learning in Python--10 basic articles

Source: Internet
Author: User

In this article we mainly study the method of finding the length of a string in Python--__len__ () Whether it is two-dimensional or one-dimensional, and its simple

Learn Python by topic:

Returns the length of the last word, given a string consisting of uppercase, lowercase letters, and spaces.

If the word does not exist in the input, 0 0 is returned.

Attention:

"word" refers to a string that does not contain a space symbol

For example:

For a string "hello World" (without quotation marks), the returned result is 55;

For "abc abc " a string (without the quotation marks), the returned result is 33.

Input format

Enter only one row for the string ss (length not exceeding 1000010000).

Output format

The length of the last word in the output s S.

Sample Input 1
Today is a nice day
Sample Output 1
3
Sample Input 2
The quick brown fox jumps over the lazy dog   
Sample Output 2
3
It is just the length of the last word, two times the length is good.
3.5 #-*--coding:-utf8--*-x=input (). Split () len=x.__len__ ()if len==0  :    print (0)else:    y=x[len-1]    print (y.__len__ ())

The path to learning in Python--10 basic articles

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.