Python Cultivation 2

Source: Internet
Author: User

Python Development Ide:pycharm, Elipse

1. Operators

    

1        1. Arithmetic operation   +  -*///  * *  % 2  3 2. Assignment operation   A = 1   a + = 2
   
     4 
     5 3. Comparison operation    1>3  
     6 
     7 4. Logical Operation    
    or
    and 1>3 8  9 5. Member Operation     "ab"in   /not
      in    "abce"
   

Number (int)

                       Int Common operation converts                           a string to a numeric int ("123") to                           view the data type              (                           10        ) convert the binary to the default of the binary of the =2/ 8/16)                           Current number, at least binary N-bit       num.bit_length ()
View Code           

String (str)

#capiltalize First Letter CapitalA ="SB"Print(A.capitalize ()) Casefold Lowera="Sb"Print(A.casefold ())#lowercase But unknown to other countriesPrint(A.lower ())#lower for common variable lowercasea="Sdjha"         Print(A.lower ())#into lowercasePrint(A.upper ())#into uppercaseCenter#Set the width and center the set contentA ="Sb"Print(A.center (20,"*"))>>>*********sb*********#set width, Align leftTest ="Alex"v= Test.ljust (20,"*")Print(v)#set width, align rightTest ="Alex"v= Test.rjust (20,"*")Print(v) Count#index The number of occurrences of the character or concatenated character (look for the number of occurrences of the subsequence)A ="Sb" Print(A.count ("b"))>> 1Test="ALEXALEXR"In fact and end position v= Test.count ('ex', 5,6)Print(v) endswith/does StartsWith end with what begins with a="Sb"Print(A.endswith ("b"))Print(A.startswith ("b") )>>True>>False#¥¥¥expandtabs (), Segmentation (tab use) through \ tTest ="Username\temail\tpassword\nlaiying\[email Protected]\t123\nlaiying\[email Protected]\t123\nlaiying\[email Protected]\t123"v= Test.expandtabs (20)Print(v)#¥¥¥¥ndex index position, can not find errorA ="Sb"Print(A.index ("b"))>>1#¥¥¥¥¥find index position, location is not found-1A ="Sb"Print(A.find ("b") )>>1#format formatting, specifying a value for a string positionA ='I Love{name} {a}'Print(A.format (name =' You', a ="jingjing"))#>>>i Love Jingjing#Format_map # Return the keys value to name aA ='I Love{name} {a}'Print(A.format_map ({"name":' You',"a":"jingjing"}))#"" I lov eyou,jingjinga="pidalfj1233"   #whether the string contains only alphanumericPrint(A.isalnum ()) "Truea="ABC"                #whether the character passed is a letter, a manPrint(A.isalpha ()) "True test="as2df"v= Test.isalpha ()#whether the current input is a number  Print(v) issspace ()#is not a spaceA ="   "Print(A.isspace ())>>True#whether there are non-visible characters#\ t Tab#\ nthe line break#SpaceTest ="oiuas\tdfkj"v=test.isprintable ()Print(v)#determine if all are spacesb =""v=b.isspace ()Print(v)#istiltle #是不是标题 (capital letters)A =" is the men"Print(A.istitle ()#isupper islowerA ="Aa"Print(A.isupper ())#are they all uppercase?Print(A.islower ())#are they all lowercase?#$$$$$$ each element in a string to be spliced with a specified delimiterTest ="you are the wind, I am the sand"Print(test) T=' 'v="_". Join (Test)Print(v)>>>you are the wind, I am the sand>>>You _ is _ the Wind _ son _ i _ is _ Sha#$ $lstrip/rstrip/strip #remove The left side of the space/right space/left and right space (specify the parameters to delete the characters inside)A ="ABC c"Print(A.lstrip ())Print(A.rstrip ())Print(A.strip ()) Example: Remove the specified string with a limited maximum match test="xa"v= Test.lstrip ('xa') v= Test.rstrip ('9lexxexa') v= Test.strip ('xa')Print(v)#Split to specified number#v = test.split (' s ', 2)#Print (v)#Test.rsplit ()#split, only according to, True,false: whether to keep line breaksTest ="ASDFADFASDF\NASDFASDF\NADFASDF"v=test.splitlines (False)Print(v)#uppercase and lowercase conversionsTest ="ALex"v=test.swapcase ()Print(v)#letter, number, underline: identifier Def classA ="def"v=A.isidentifier ()Print(v)#replaces the specified string with the specified stringTest ="Alexalexalex"v= Test.replace ("ex",'BBB')Print(v) v= Test.replace ("ex",'BBB', 2)Print(v)
View Code

Common: Join split find strip upper lower lower replace

     Str simple operation

       Slice Str[0:2] # refers from the first to the second character

Index subscript to get a string in a string str[2]

······

      

        

            

Python Cultivation 2

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.