Python third day: data type

Source: Internet
Author: User

"" "# String index with slice # string All operations will not change the original string, will only generate a new string s =" ABCDEFGHIGKLM "S1 = s[0] Print (S1) # Gu Tou disregard tail string slicing    S2 = s[0:2] Print (s2) s3 = s[:] # Get all strings print (s3) S4 = s[::-1] # reverse all add-1 print (s4) S5 = S[::3] # [First: Tail: Step] Print (s5) s6 = s[::-2] Print (s6) s7 = s[4:0:-2] Print (s7) "" "# string-related operation name =" Break Dyj "# First letter Uppercase STR1 = Name.capitalize () print (STR1) # full capital, all lowercase str2 = name.upper () STR3 = Name.lower () print (str2, STR3) # case Flip STR4 = Name.swa Pcase () print (STR4) # header uppercase special characters are capitalized (numbers are also special characters) STR5 = "My-name/is*break" STR6 = Str5.title () print (STR6) # left and right padding STR7 = " Break "Str8 = (+,"-") print (STR8) # is not full 8 bits, will put the previous position all add eight bits, full eight will be complete 16 bits STR9 =" Bbbbbbbbbb\tak "Print (STR9) Str10 = Str9.expandtabs () print (STR10) # with what is the case for the beginning (string, start, end) Str11 = Str7.startswith (' Break ', 0, 5) print (STR11) # Find the index by the element to find a return index, can not find the return -1->find# through the element to find the index to find the return index, can not find the error->index_int = Str9.index ("b") _int2 = Str9.find ("b") Print (_ INT,_INT2) # Strip Rstrip Lstrip-around simultaneous deletion only delete rightLeft str12 = "break" Str13 = Str12.strip ("b") print (Str13) # find string Number Str14 = Str9.count ("BBB", 2, 5) print (STR14) # string Split str15 = "b , r,e,a,k "list = Str15.split (", ") print (list) # Format of the three-in-play formatted output s =" I'm {}, this year {} years old, hobby {}, say again, my name {} ". Format (" Break ", 19," Girl "," Break ") print (s) s =" I call {0}, this year {1} years old, hobby {2}, again, my name is {0} ". Format (" Break ", +," Girl ") # inside Write index print (s) # name = input (" Please lose Into your name: ") s =" My Name {name}, this year {age}, hobby {hobby}, again, my name {name} ". Format (Name=name, age=19, hobby=" Girl ") print (s) # string Substitution str_ = "W got KFC Oscar inside the Rafah subject Dallas KFC" str_1 = Str_.replace ("KFC", "Break", 1) # old New num default all replace print (str_1) # is series _str = "Asdjnasjk1  118564 "Print (_str.isalnum ()) # Whether the string is composed of letters and arrays print (Str_.isdigit ()) # String Whether it is made up of numbers print (Str_.isalpha ()) # strings are composed of letters T = "Mobile card hunan everyone look at Cang jing empty" If "Cang jing Empty" in T:print ("The characters you entered contain sensitive words ...") for I in T:print (i)


Python third day: data type

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: 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.