Self-learning Python full stack development fourth notes (Python Common data types, strings)

Source: Internet
Author: User
Tags string format

Start learning Python's Common data types today.                The base data type; the numeric int string str boolean bool-list tuple dictionary Dict all strings or numbers, dictionaries, and methods exist corresponding to the "value" in the "values" Press CTRL + Left click to display the template is the class (Int,str,bool ... Template creation is not a value is an object relationship: All objects have functions that correspond to the class.
    1. View the capabilities of an object's class or object
A. By Type temp = "Alex" t = Type (temp) print (t) # # #如果显示str, CTRL + Left click to find the Str class, all internal methods
    1. temp = "Alex"
b= Dir (temp)
    1. by Help,type
    2. Direct click
temp = "Alex" Temp.upper () mouse on upper, CTRL + Left click, Auto-navigate to upper function explained ret = N1 () no parameter ret = N1 (2) Pass      A parameter ret = n1 (2,ABC,CAA) passed three parameters self means no parameters are passed Self,with,fill up to two parameters self star = None Default value (can not be transmitted) Basic data Types Common features:
    1. integer int
A. #n1 = 123 #n2 = 456 #print (n1+n2) #print (n1._add_n2) b. Gets a binary minimum number of digits n1 = 4 #000000/00 ret = n1.bit_length () print (ret)
    1. Initial uppercase capitalize (self)
A1 = "Qiao" ret = A1.capitalize () print (ret) # # #打印Qiao
    1. Center (Self,width,fillchar=none)
"" "Content centered, Width: total length; Fillchar: blank padding content default No" "" a1 = "Qiao" net = A1.center ("*") print (ret) # # #打印--------Qiao--------
    1. Count (Self,sub,star=none,end=none)
"" "Sub-sequence Number" "" A1 = "Qiao" ret = A1.count ("a") print (ret) /ret = A1.count ("A", 0,3) 0 = q 1 = i 2 = a # # #打印1 (A has 1 occurrences)
    1. EndsWith (Self,suffix,start=none,end=none)
"" "whether to end with XXX" "" a1 = "Qiao" ret = A1.endswith ("0") gets a character greater than 0 less than 2            Position print (ret)/ret = A1.endswith ("0", 0,2) # # #打印Ture/false
    1. Expandtabs (self,tabsize = None)
"" To convert the tab to a space, the default one tab to 8 spaces "" "CONTENT =" HELLO\TQQQ "Print (content) print (Content.expand                  Tabs ()) print (Content,expandtabs ()) # # #hello 999 Hello 999 Hello 999
    1. Find (Self,sub,star = None,end = None)
"" "Look for the sub-sequence position, if not found return-1" "s =" Qiao Hello "print (S.find (" AO ")) # # #打印2 (from the beginning to the back, find the first one) if you cannot find the display" -1 "
    1. Format (*args,**kwargs)
"" "string format, dynamic parameter" "" s = "Hello{0},age{1}" print (s) #{0} placeholder new = S.format ("Qiao" , print (New1) # # #打印hello {0},age{1} Hello Qiao,age19
    1. Join (self,iterable)
"" "" "" "" "" "" Li = ["Qiao", "Wang"] #列表 [] () tuple s = "_". Join (LI) print (s) # # #打印qiao_wang
    1. Lstrip (self,chars = None) Rstrip (remove right margin) strip (remove both sides)
"" "Remove left blank" "" s = "qiao" news = S.lstrip () print (News) # # #打印qiao ... ... qiao
    1. Partition (SELF,SEP)
"" "Split, before, in, after three sections" "" s = "Alex sb Alex" ret = s.partition ("SB") print (ret) # # #打印 ( ' Alex ', ' SB ', ' Alex ') tuple type
    1. Replace (Self,old,new,count = None)
"" "Replace" "" s = "Alex SB Alex" ret = S.replace ("Al", "BB") ("Al", "BB", from left to right first) p Rint (ret) # # #打印bbex SB Bbex
    1. Rstip (self,chars = None)
"" "Split" "" s = "Alexalex" ret = S.split ("E") ("E", 1) print (ret) # # #打 Indian [' Al ', ' xal ' x ']
    1. Swapcase (self)
"" "uppercase lowercase, lowercase to uppercase" "" s = Qiao print (S.swapcase ()) # # #打印qIAO
    1. Title (self)
            "" "Conversion title" "            s =" The school "            ret = s.title ()         & nbsp   Print (ret)             # # #打印TheSchool索引s = "Alex" Print (S[0]) print (s[1]) Print (s[2]) print (s[3] # # #打印alex     length s = "Alex" ret = Len (s) print (ret) # # #打印4 (with 4 bits, starting from 0)    Slice s = "Alex" Print (S[0:2])            >=0   <2   (0,1) # # #打印al    f or loop, Break,continue can refer to S = "Alex" for item in S:    print (item)           (item is variable name) # # #打 Print alex                        continues = "Alex" for item I N S:    if item = = "L"         continue   print (item) # # #打印aex     &N Bsp         &NBSP;         breaks = "Alex" for item in s:    if item = = "L"         BREAK&NB Sp   Print (item) # # #打印a    for item in S:           (item is the variable name, At random) (S is the thing to loop) finally finished finishing. Good tired, backache backache. Later can not accumulate so much knowledge and then tidy up the blog, must be timely collation, good night.

Self-paced Python full stack development fourth notes (Python Common data types, 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.