Fourth, the senior operating and calling integer, string, list

 

String: 1. String index, str [Start index: index end: step]
length 2.len (str) string
3. member operator: in, not in: determining whether the character string in strings print ( "na" in in or not "name")
4. variable name .strip ( ""): to remove the character on both sides, .rstrip () to the right, .lstrip () to the left (to space)
5. variables name .split ( "|", n)used to split the string, n represents the number of split, all divided by default, it points out that the list
6. variable name .find ( "str"), used to query whether the characters in inside
7. the variable name .replace ( "old" and "new"), replace string

 

 

 


List: 1. Slice list [start subscript: subscript end: step], from left to right, regardless of the end bone
2. Variable name .append () added to the list [tail] inside
3. Variable name .insert (n-, m) increases to the specified position, n being the index, m is the added data
4. variable name .extend (n, l) n is an index, can be added one by one list to another list

 

1.del list [] Delete List
2. Variable name .remove ( "m"), directly delete a specified element
3. The variable name .pop (), from the tail default deletion, can also be specified, delete the value may be returned
4.clear ()--clear the list
















# A. Integer (int)

# = basic use ====================================== =====================================
# 1, use: keep qq number, phone number, do not ID number ... lettered
# 2, define how
Age Age = 18 is # = int (18 is)
# int ( 'dsjfjdsf')
# int ( '1.1') can turn int # pure digital string of decimal point will not work

# hex conversion

# 10 other binary transfer binary
## binary decimal 0,1
# 10 # 1 * (2 * 1) + 0 * (2 ** 0) 2
# octal, decimal turn 0-7
# 235 # 2 * (8 * 2) + 3 * (8 * 1) + 5 * (8 * 0)
# hex decimal turn the AF 0-9
# 217 # 2 * (2 ** 16 ) +. 1 * (16 **. 1) +. 7 * (16 ** 0)
Print (int ( '1100 is', 2)) # int can pass the first parameter, the first parameter is represented by what is in the end feed then made to decimal
Print (int ( '14',. 8))
Print (int ( 'C', 16))




# 10 revolutions decimal radix.
# 10 hexadecimal binary switch
# print (bin (12))0b1100 0b behind the figures represent a binary number is
# 10 decimal turn octal
# Print (oct (12)) # 0o14 0o indicates that the following number is octal 14 >>> 1 * (8 * 1) + 4 * (8 * 0))
# 10 hex 16 hex switch
# Print (hex (12)) # 0xc 0x indicates that the following number is a hexadecimal number


# 3, + common operations built-in method
# ===================== the type of summary ================= ============================== ======
# a stored value
# ordered or disordered
# ordered: whenever there is data ordered index




# variable type immutable
"" "
variable type: if the value of change , id unchanged, indicating that you change the original value (a list of tuples, dictionaries are all variable type)
immutable: when the value is changed, id must change as: string
"" "
X = 10
Print ( ID (X))
X =. 11
Print (ID (X))




# float
# effect: height and weight pay
# = 1.1 # the salary a float (1.1)
RES = a float ( '1.11')
Print (type (RES))

# II. String
# ====================================== ==== Basic Usage ==================================
# 1, uses: descriptive
# 2, is defined by: '', "", "" "" ""
# S = 'Hello Baby' # STR ( 'Hello Baby')
# S1 = STR ([1,2,3,4])
# Print (type (S1))
# S2 = STR ({ 'name': 'Jason', 'password': 123})
# Print (type (S2))


#. 1, according to the index value (forward + reverse take take): only take
# s = 'hello Baby ~ big '
# Print (S [0]) # H
# 2, a slice (care regardless of the end, step): the interception of a new small strings from a larger string
# head is fixed to the left, to the right fixed that bit is not to say by number of points craniocaudal
# Print (S [0:. 5]) # Hello
# Print (S [0: 10:. 1]) # Hello step is not written by default. 1
# Print (S [0: 10: 2]) # indicates every few steps take a
#Learn negative value
# Print (S [-1] # ~
# Print (S [0:. 5:-2]) # default values slices left to right, right to left is negative
# print (s [5: 0 : -1]) # olle
Print # (S [-1: -10: -1]) # ybab GIB ~


#. 3, the length len: statistics is the number of characters in the string
# S1 = 'Hello'
# Print (len (S1))
# 4, in operation members and not in: determining whether there is a substring in the larger string a
# Print ( 'Egon' in 'Egon Egon iS and iS DSB SB')
# Print ( 'G' in 'iS Egon SB and Egon iS DSB ')
# Print (' Jason 'Not in' Egon Egon iS and iS DSB SB ')


#. 5, left and right sides of the character string to remove the strip, regardless of intermediate
# username = input (' >>>: ') .strip ()
# username IF ==' Jason ':
# Print (' Good Job ')
# Strip () remove the default string end to end spaces
method # uniform application built using the symbol period ().
NAME1 = #' Jason '
# = NAME2' Jason '.strip ()
# Print (== NAME1 NAME2)
# NAME3 =' ON $$$$ $$$$$ EG $ '
# Print (NAME3.strip ( '$')) # end to end on both sides of the stuff you have entered remove
# Learn to
# name4 = '% ¥ # jason & *)'
Print # (name4.strip ( '# ¥%)'))
# The rstrip () the lstrip ()
# = NAME5 'Jason $$$$ $$$$'
# Print (name5.lstrip ( '$')) # left left
# print (name5.rstrip ( '$' )) # the right right

#. 6, segmentation split: some delimiter character strings for tissue, can be cut into split list, the value for further
data = ' JASO | n-| 123 | Handsome '
# Print (data.split (' | '))
# username, password, info = data.split (' | ')
# Print (username, password, info)
# emphasized: split segmentation out of the data type is a list
# print (data.split ( 'o' )) actually cut # order from left to right in
the order of # print (data.split ( 'o' , 1)) # actually cut the left the right
# print (data.rsplit ( 'o' , 1)) # order from left to right actually cut
# If not specified, the split effect is the same rsplit and

# 7, cycle
# for I in Data:
# Print (i)
# you need to master
# 1, strip,lstrip,rstrip
#2、lower,upper
S = # 'JaS1oN'
# s.lower RES = ()
# Print (RES)
# Print (S)
# Print (s.upper ())
# Print (S)
# calling string method does not change the string itself


. 3 #, startsWith, endsWith
S1 = 'Egon DSB IS'
# Print (s1.startswith ( 'E')) # determines whether the string to begin with what
print (s1.endswith ( 'n') ) # determines whether the string What end to


# 4, format three play (Python do recommended format output format)
# occupying a first position according to the principles consistent with the% s
# str1 = 'my name is { } my age is {}' .format ( 'Jason', 18 is)
# str1 = 'My name Age IS IS {} {} My'. the format (18 is, 'Jason',)
# Print (str1)
# according to the second index placeholder
# str1 = 'My. 1} {0} {My name IS {0} {0} Age IS'. the format ( 'Egon', 18 is)
# Print (str1)
# third placeholder name names (keyword parameter passing)
# Str1 = 'My {name} name IS {Age} My {name} Age IS {name}'. The format (name = 'Jason', Age = 18 is)
# # Print (str1)

#. 5, Split, rsplit
#. 6 , the Join
# Data = 'Jason | 123 | Handsome'
# res_list = data.split ( '|')
# Print (res_list)
#
. # res_str = '$' the Join (res_list) # container by multiple elements of the type splicing the specified character string as a
# Print (res_str)
# L = [ '. 1', 'a', 'B']
# RES = '|' .join (L)
# Print (RES)


#. 7, Replace
# STR = 'Egon Egon IS and IS DSB SB of He has BENZ A'
# str.replace RES = ( 'Egon', 'Kevin',. 1)
# Print (RES)
# Print (STR)


#. 8, the string is determined isdigit # whether contained pure digital
# the while True:
# Age = INPUT ( '>>>:')
# if age.isdigit():
# age = int(age)
IF Age #> 28:
# Print ( 'good aunt')
# the else:
# Print ( 'Will you take your fucking lose')









# need to know about the built-in method
# 1, the Find, rfind, index, rindex, COUNT
S = 'Kevin Kevin iS and O iS DSB SB'
# Print (s.find ( 'DSB')) # returns the index value of d-characters located
# print (s.find ( 'xxx' )) # can not be found when no error is returned -1
# Print (s.find ( 'I', 0,3)) # can also be limited by the look index
# print (s.index ( 'o' )) # returns pass character where the index value
# print (s.index ( 'i' , 0,3)) # returns the index value of the transmitted character where the
number # print (s.count ( 'n' )) # statistical character appears


# 2, Center, ljust, the rjust, zfill
S9 = 'Jason'
# Print (s9.center (12 is, '*'))
# Print (s9.ljust (40, '$'))
# Print (s9.rjust (40, ' $ '))
# Print (s9.rjust (40,''))
# Print (s9.zfill (40))

# 3, expandtabs

S10 = # 'A \ TBC'
# Print (s10.expandtabs (100))

#. 4, captalize, swapcase, title
# S12 = 'HELLO WORLD SH10'
# Print (s12.capitalize ()) the Hello World initials #
# print (s12.swapcase ()) # invert case
# print (s12.title ()) # size of the first letter of each word

# # 5, is a digital series
# num1 = B'4 '#Bytes in
# num2 = U '4' # unicode, python3 without adding u is the Unicode
# num3 = 'One' Chinese digital #
# num4 = 'Ⅳ' # Roman numerals
# # '' .isnumeric (): unicode, Chinese numerals, Roman numerals, insofar as it represents identification numbers are
# print (num2.isnumeric ())
# print (num3.isnumeric ())
# print (num4.isnumeric ())
#
# # '' .isdecimal (): Common Unicode recognizes only Arabic numerals
# print ( num2.isdecimal ())
# Print (num3.isdecimal ())
# Print (Num4.isdecimal())
#
# # '' .Isdigit (): bytes, using unicode isdigit under normal circumstances would have been to meet the needs of the
# Print (num1.isdigit ())
# Print (num2.isdigit ())
# Print (num3.isdigit ())
# Print (num4.isdigit ())


#. 3, common operations + built-in method
# ================================ the type of summary ==================================== ======
# store a value
# ordered (ordered: whenever data is ordered indexed)
# immutable

query string replacement
= str1 "Hello itcast" 
Print (str1.find ( "itcast"))
Print (str1.find ( "0"))
str2 = str1.replace ( "itcast", "Python") is an alternative format # Replace replace (Old , the new)
Print (str2)

III. list
# Effect: a plurality of equipment, a plurality of hobbies, many courses, a plurality of other girlfriend 

# defined: there may be [] values within a plurality of any type, separated by commas
# my_girl_friends = [ 'alex', 'wupeiqi', ' yuanhao ', 4,5] # = essence List my_girl_friends ([...])
# or
# L = List (' ABC ')
# L1 = List ({' name ':' Jason ',' password ':' 123 '})
# Print (L1)
# list internal principle for loop and a value of one stuffed to list


# priority control operation:
# 1, access by index value (forward + reverse access access) : may be taken to deposit
# L = [1,2,3,4]
# Print (L [0:. 4:. 1])
# Print (L [0 ::])
# Print (L [. 5 :: - . 1])
# Print (ID (L))
# L [0] = 69
# Print (ID (L))
# Print (L)
# 2, a slice (care regardless of the end, step)
L = [11,22 , 33,44,55]
L1 = [99,88,77,66]
# [11,22,33,44,55,99,88,77,66]

# 1. Add a tail 66
# L.append (66) # Note append data values can be added as a list element
# print (l)

2. anywhere additive element #
# l.insert (2,96) # additive element at an arbitrary position by the Index
# print (l) # Note insert data values can be added as a list element

# 3. Add the container type data
# l.append (l1)
# l.insert (-1, l1)
# l.extend (l1) l1 # internal principle for one loop is appended to the tail of the list
# l.extend ([. 1,])
# Print (L)

#. 3, a length of
# Print (len (L))
#. 4, the members in operation in and Not
# Print (in 444 L)
#. 5, is added to the list of elements (******)
# the append
INSERT #
# Extend

#. 6, delete
# Print (L)
# del L [2] # del delete operations for all the
# Print (L)



# = l.pop RES1 () # tail pop
# res2 = l.pop ( )
# = RES3 l.pop ()
# Print (RES1, RES2, RES3)


# = l.pop RES1 (0) can specify the index by index # pop-up element
# print (res1)


# Res = l.remove (33) # to delete the specified element value
# Print (L)
# Print (RES)

# = S 'haha'
# Print (S)
# del S
# Print (S)
#. 7, loop
in I L for:
Print (I)
































Guess you like

Origin www.cnblogs.com/wukai66/p/11127469.html