day 07 numeric string type built-in method

Integer

  1. Role
    description of age, id
  2. Define how
    X = 10
    X = int ('10 ')
    X = int (10.1)

x = int ('10 .1 ') # error

  1. Built-in way
    no built-in method, only the arithmetic and compare operations

  2. A plurality of values stored value or
    a value

  3. Orderly or disorderly orderly: the index; disorder: no index
    are they not say that

  4. Variable or non-variable (Key)
    Number type immutable

The variable is defined and invariable:
a variable (variable value terms), id value becomes the same value, the hash can
not be changed (in terms of variable values), the value becomes variable id, not a hash

Float

  1. The role of
    salary
  2. Defined method
    X = 1.11
    X = a float ( '1.11')
    X = a float ( '. 1')

  3. Built-in methods
    arithmetic and compare operations

  4. A plurality of values stored value or
    a value
  5. Ordered or disordered
    they not say that
  6. Variable or non-variable (focus)
    Immutable

String type

  1. Role
    name / sex /

  2. Defined manner
    s = 'sdfklsdjfk'

    s = b'sdkfljl '# of bytes printed type, binary type, there is such a binary 010101010100110100 # defined manner, in fact, do no

    \ N newline s = 'a \ na' # slashes met, the computer will know the next character and \ spliced ​​together have a special meaning

    \ t indented four spaces
    s = 'a \ t \ ta

    \ r rollback on a print result, a print result on covering
    print ( '\ ra', end = '') # add a \ get behind \ meaningless

    = S 'A \ Na'
    S = R & lt '\ RA \ T \ Na' # RAW, so \ lose special meaning

  3. String built-in method (only string type to use)

    Priority grasp

1) index value
Print (S [1])
2) sections
print (s [4: 0: 1]) # 1 represents left to right
print (s [-4 :: - 1 ]) # -1 represents from # not recommended right to left master
print (s [4: 0: -1]) # -1 represents right to left

3) for循环
for i in s:
print(i)

. 4) Strip ()
S1 = 'Nick Handsome'
Print (s1.strip ()) to both ends of the blank #

= S2 ' !!!!! Nick Handsome ---- '
print (s2.strip ( '- !')) # specify multiple characters removed together, as long as the strip on which some characters kill all
print (s2.strip ( 'nick')) # specify multiple characters removed together, as long as the strip on which some characters kill all
s2.strip ( '
-!') # s first determines whether the character in the string ends, is , in the strip go to find an no , there would be removed, again determined character string s ends, -!, then find strip from the inside, there is removed, without removing the stop

5) split () cut
print (s2.split ()) # default spaces cutting string
print (s2.split ( '!') ) # In! Cut
print (s2.split ( '!', 2)) # to! Cutting, cutting two
6) in or in Not
Print ( '*' in S2) # True
Print ( '$' Not in S2) # True
. 7) length len
S2 = 'Nick Handsome'
Print (len (S2)) # required length of the string

Need to know

1) lstrip() 和 rstrip()
s2 = '!!!!!nick handsome----'
print(s2.lstrip(''))
print(s2.rstrip('
'))

2) rsplit()
print(s2.split('', 1))
print(s2.rsplit('
', 1))

3) lower&upper()
s3 = 'aaabbJ'
print(s3.lower())
print(s3.upper())

4) startswith&endswith()
s3 = 'aaabbJ'
print(s3.startswith('b'))
print(s3.endswith('J'))

5) join (with more) combined with the general and split
s3 = ''
Print (s3.join ([ '234', '234', '234'])) # s3 as to break character, the list of splice each element

s = 'hot strip / chips / soda / noodles / ham / wolfberry / Angelica / velvet'

s1 = s.split('/')
print('*'.join(s1)

6)replace

s2 = 'yongjiu handsome'

print (s2.replace ( 'yongjiu', 'gebilaowang'))

7) isdigit (purely digital) / isalpha (plain letters)
S2 = '12312'
Print (s2.isdigit ())

​ s3 = 'aaac1c'
​ print(s3.isalpha())

To understanding

1) the Find | rfind | index | rindex | COUNT
s2 = ' 23423 ni234234ck $$ hand223423some *****'
01234567891011
Print (s2.find ( '$')) # left to find, find the first stop, can not be found to return -1
Print (s2.rfind ( '$')) # right to find, locate stopped, can not be found or -1

print (s2.index ( '$') ) # can not find the error
print (s2.rindex ( '$') ) # can not find the error

Center | ljust | rjust | zfill
s2 = 'Nick Handsome'
Print (s2.center (50, ' ')) # centered
Print (s2.ljust (50, '
')) # Left
print (s2. rjust (50, '*') ) # right home
print (s2.zfill (50)) # 0 is filled right home

2) expandtabs
S2 = 'A \ TA'
Print (S2)
Print (s2.expandtabs (. 8)) for # \ t purposes

captalize | swapcase | title only for the English
s2 = 'harry Potter'

print (s2.capitalize ()) # initials (the beginning of the sentence) uppercase, lowercase other, in the opening paragraph with
print (s2.swapcase ()) # invert case
print (s2.title () ) # all words capitalized

3) is series (they know who are interested)

4. The stored value or a plurality of values
a value

The ordered or unordered
orderly

6. The variable or non-variable (focus)
immutable

Guess you like

Origin www.cnblogs.com/wwei4332/p/11289849.html