Python数据类型及其方法详明,设计形式之
分类:计算机编程

图片 1图片 2

1.angular.bind()

Python数据类型及其方法详整

大家在求学编制程序语言的时候,都会蒙受数据类型,这种望着很基本功也不引人侧目的东西,却是非常重大,本文介绍了python的数据类型,并就每一种数据类型的艺术作出了详实的叙说,可供知识回看。

图片 3

  1 /*2048*/
  2 
  3 #include<stdio.h>
  4 #include<stdlib.h>
  5 #include<conio.h>
  6 #include<time.h>
  7 
  8 void print(void);/*显示游戏界面*/
  9 int add(void);/*对中间变量数组进行处理*/
 10 
 11 int code[4][4] =
 12    {
 13     {0,0,0,0},
 14     {0,0,0,0},
 15     {0,0,0,0},
 16     {0,0,0,0},
 17    };/*游戏中的16个格子*/
 18 int temp[5];/*中间变量*/
 19 int move = 0;/*移动次数*/
 20 int score = 0;/*分数*/
 21 
 22 
 23 
 24 int main(void)
 25 {
 26      int gameover = 0;/*判断游戏是否结束,1结束,0继续*/
 27      int i,j;
 28      int change = 1;/*判断格子中的数是否改变,0不变*/
 29      char input;
 30      srand((unsigned)time(NULL));/*设置随机数的起点*/
 31      while(gameover == 0)
 32          {
 33               if(change >= 1)/*仅当数发生改变时添加新数*/
 34                {
 35                     do
 36                      {
 37                           i=((unsigned)rand()) % 4;
 38                           j=((unsigned)rand()) % 4;
 39                      }while(code[i][j] != 0);
 40                     if(((unsigned)rand()) % 4 == 0)
 41                      {
 42                           code[i][j]=4;
 43                      }
 44                     else
 45                      {
 46                           code[i][j]=2;/*随机选一个空格填上2或4*/
 47                      }
 48                     move  ;/*增加次数*/
 49                }
 50               print();/*显示*/
 51               input = getch();/*输入方向*/
 52               change = 0;
 53               switch(input)
 54                    {
 55                         case '0':/*退出*/
 56                                  printf("Are you sure to exit?(y/n)");
 57                                  input=getchar();
 58                                  if(input=='y'||input=='Y')
 59                                     exit(0);
 60                                  break;
 61 
 62                         case 'W':
 63 
 64                         case 'w':/*上*/
 65                                  for(j=0;j<=3;j  )
 66                                    {
 67                                         for(i=0;i<=3;i  )
 68                                           {
 69                                                temp[i]=code[i][j];/*把一列数移到中间变量*/
 70                                           }
 71                                         temp[4]=0;
 72                                         change  = add();
 73                                         for(i=0;i<=3;i  )
 74                                           {
 75                                                code[i][j]=temp[i];/*把处理好的中间变量移回来*/
 76                                           }
 77                                     }
 78                                   break;
 79 
 80                         case 'A':
 81 
 82                         case 'a':/*左*/
 83                                  for(i=0;i<=3;i  )
 84                                    {
 85                                         for(j=0;j<=3;j  )
 86                                           {
 87                                                temp[j]=code[i][j];/*把一行数移到中间变量*/
 88                                           }
 89                                         temp[4]=0;
 90                                         change  = add();
 91                                         for(j=0;j<=3;j  )
 92                                           {
 93                                                code[i][j]=temp[j];/*把处理好的中间变量移回来*/
 94                                           }
 95                                    }
 96                                  break;
 97 
 98                         case 'S':
 99 
100                         case 's':/*下*/
101                                  for(j=0;j<=3;j  )
102                                    {
103                                         for(i=0;i<=3;i  )
104                                           {
105                                                temp[i]=code[3-i][j];/*把一列数移到中间变量*/
106                                           }
107                                         temp[4]=0;
108                                         change  = add();
109                                         for(i=0;i<=3;i  )
110                                           {
111                                                code[3-i][j]=temp[i];/*把处理好的中间变量移回来*/
112                                           }
113                                    }
114                                  break;
115 
116                         case 'D':
117 
118                         case 'd':/*右*/
119                                  for(i=0;i<=3;i  )
120                                    {
121                                         for(j=0;j<=3;j  )
122                                           {
123                                                temp[j]=code[i][3-j];/*把一行数移到中间变量*/
124                                           }
125                                         temp[4]=0;
126                                         change  = add();
127                                         for(j=0;j<=3;j  )
128                                           {
129                                                code[i][3-j]=temp[j];/*把处理好的中间变量移回来*/
130                                           }
131                                    }
132                                  break;
133                    }
134               gameover=1;
135               for(i=0;i<=3;i  )
136               for(j=0;j<=3;j  )
137               if(code[i][j]==0)
138               gameover=0;/*所有格子都填满则游戏结束*/
139         }
140     printf("Game over!n");
141     getch();
142 
143     return 0;
144 }
145 
146 void print(void)/*显示游戏界面*/
147 {
148     int i,j;
149     system("CLS");/*清屏*/
150     printf("2048n");
151     printf("W--UP A--LEFT S--DOWN D--RIGHT 0--EXITn");
152     printf("Score:%d Move:%dn",score,move);
153     printf("Made by lanshanxiaon");
154     printf("|-----------------------|n");/*显示横向分隔线*/
155     for(i=0;i<=3;i  )
156        {
157            for(j=0;j<=3;j  )
158               {
159                    if(code[i][j]==0)
160                      {
161                           printf("|     ");/*0显示空格*/
162                      }
163                    else
164                      {
165                           printf("|]",code[i][j]);/*显示数字和分隔线*/
166                      }
167               }
168            printf("|n|-----------------------|n");/*显示横向分隔线*/
169        }
170 }
171 
172 int add(void)/*对中间变量数组进行处理*/
173 {
174     int i;
175     int t=0;
176     int change=0;/*判断数组是否有改变,0不变,1变化*/
177     do
178      {
179           for(i=0;i<=3;i  )
180             {
181                  if(temp[i]==0)
182                   {
183                        if(temp[i]!=temp[i 1])
184                          change=1;/*当一个0后面不是0时数组改变*/
185                        temp[i]=temp[i 1];
186                        temp[i 1]=0;
187                   }
188             }/*去掉中间的0*/
189           t  ;
190      }while(t<=3);/*重复多次*/
191     for(i=1;i<=3;i  )
192         {
193              if(temp[i]==temp[i-1])
194               {
195                    if(temp[i]!=0)
196                      {
197                           change=1;/*当两个非零相同的数相加时数组改变*/
198                           score=score temp[i];/*加分*/
199                      }
200                    temp[i-1]=temp[i-1]*2;
201                    temp[i]=0;
202               }
203         }/*把两个相邻的相同的数加起来*/
204 
205     return change;
206 }

图片 4图片 5

生龙活虎、整型和长整型

整型:数据是不带有小数部分的数值型数据,例如大家所说的1、2、3、4、122,其type为"int"

长整型:也是生龙活虎种数字型数据,然而通常数字相当大,其type为"long"

在python第22中学分别整型和长整型,在三拾伍个人的机械上,取值范围是-2147483648~2147483647,超过范围的为长整型,在六十几个人的机器上,取值范围为-9223372036854775808~9223372036854775807(平常也与python的解释器的位数有关)。

在python3中,不设有整型和长整型之分,唯有整型。

举例:

图片 6图片 7

python2中
number = 123
print (type(number))
number2 = 2147483647
print (type(number2))
number2 = 2147483648    #我们会看到超过2147483647这个范围,在py2中整形就会变成长整形了
print (type(number2))
#运行结果
<type 'int'>
<type 'int'>
<type 'long'>
#python3中
number = 123
print (type(number))
number2 = 2147483648   
print (type(number2))    #在python3中并不会
#运行结果
<class 'int'>
<class 'int'>

View Code

常用的method的如下:

.bit_length()

取最短bit位数

图片 8图片 9

  def bit_length(self): # real signature unknown; restored from __doc__
        """
        int.bit_length() -> int

        Number of bits necessary to represent self in binary.
        >>> bin(37)
        '0b100101'
        >>> (37).bit_length()
        6
        """
        return 0

View Code

举个例子:

图片 10图片 11

number = 12  #1100 
print(number.bit_length())
#运行结果
4

View Code

 

原型情势正是从一个指标在开立其它八个对象,无需了然其余创制的内部情状:(克隆)

View Code

<!DOCTYPE HTML>
<html ng-app>
<head>
</head>
<script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>
</body>
<script>
  /*  angluar.bind(obj,fn,[args]) 把对象绑定到函数里,生成新的函数  */
    var obj={name:'xiaoming'};
    var fn= function (arg) {
        console.log(this.name ' is ' arg);  // this 指 obj
    }
    var f1=angular.bind(obj,fn,'so handsome'); // 参数可选
    f1();
    var f2=angular.bind(obj,fn);          // 可在最后才传参数
    f2('weak!');
</script>
</body>
</html>

 二、浮点型

 浮点型能够看形成是小数,type为float。

图片 12图片 13

#浮点型
number = 1.1
print(type(number))
#运行结果
<class 'float'>

View Code

 常用method的如下:

.as_integer_ratio()

回来元组(X,Y卡塔尔(英语:State of Qatar),number = k ,number.as_integer_ratio() ==>(x,y) x/y=k

图片 14图片 15

    def as_integer_ratio(self): # real signature unknown; restored from __doc__
        """
        float.as_integer_ratio() -> (int, int)

        Return a pair of integers, whose ratio is exactly equal to the original
        float and with a positive denominator.
        Raise OverflowError on infinities and a ValueError on NaNs.

        >>> (10.0).as_integer_ratio()
        (10, 1)
        >>> (0.0).as_integer_ratio()
        (0, 1)
        >>> (-.25).as_integer_ratio()
        (-1, 4)
        """
        pass

View Code

 举个例证

图片 16图片 17

number = 0.25
print(number.as_integer_ratio())
#运行结果
(1, 4)

View Code

.hex()

 以十四进制表示浮点数

图片 18图片 19

    def hex(self): # real signature unknown; restored from __doc__
        """
        float.hex() -> string

        Return a hexadecimal representation of a floating-point number.
        >>> (-0.1).hex()
        '-0x1.999999999999ap-4'
        >>> 3.14159.hex()
        '0x1.921f9f01b866ep 1'
        """
        return ""

View Code

 举个例证

图片 20图片 21

number = 3.1415
print(number.hex())
#运行结果
0x1.921cac083126fp 1

View Code

.fromhex()

将十七进制小数以字符串输入,再次来到十进制小数

图片 22图片 23

    def fromhex(string): # real signature unknown; restored from __doc__
        """
        float.fromhex(string) -> float

        Create a floating-point number from a hexadecimal string.
        >>> float.fromhex('0x1.ffffp10')
        2047.984375
        >>> float.fromhex('-0x1p-1074')
        -5e-324
        """

View Code

比方

图片 24图片 25

print(float.fromhex('0x1.921cac083126fp 1'))
#运行结果
3.1415

View Code

.is_integer()

认清小数是还是不是整数,举个例子3.0为一个寸头,而3.1不是,重回布尔值

图片 26图片 27

    def is_integer(self, *args, **kwargs): # real signature unknown
        """ Return True if the float is an integer. """
        pass

View Code

比方

图片 28图片 29

number = 3.1415
number2 = 3.0
print(number.is_integer())
print(number2.is_integer())
#运行结果
False
True

View Code

 

以创制简历为例:

2048小游戏代码在地方的View Code中,将加号展开就足以看来。

View Code

三、字符类型

字符串便是一些列的字符,在Python中用单引号可能双引号括起来,多行能够用三引号。

图片 30图片 31

name = 'my name is Frank'
name1 = "my name is Frank"
name2 = '''my name is Frank
I'm 23 years old,      
       '''
print(name)
print(name1)
print(name2)
#运行结果
my name is Frank
my name is Frank
my name is Frank
I'm 23 years old  

View Code

常用method的如下:

.capitalize()

字符串首字符大写

图片 32图片 33

  def capitalize(self): # real signature unknown; restored from __doc__
        """
        S.capitalize() -> str

        Return a capitalized version of S, i.e. make the first character
        have upper case and the rest lower case.
        """
        return ""

View Code

举个例证

图片 34图片 35

name = 'my name is Frank'
#运行结果
My name is frank

View Code

.center()

字符居中,钦定宽度和填充字符(默以为空格)

图片 36图片 37

  def center(self, width, fillchar=None): # real signature unknown; restored from __doc__
        """
        S.center(width[, fillchar]) -> str

        Return S centered in a string of length width. Padding is
        done using the specified fill character (default is a space)
        """
        return ""

View Code

举个例证

图片 38图片 39

flag = "Welcome Frank"
print(flag.center(50,'*'))
#运行结果
******************Welcome Frank*******************

View Code

.count()

计量字符串中某些字符的个数,能够钦赐索引范围

图片 40图片 41

    def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.count(sub[, start[, end]]) -> int

        Return the number of non-overlapping occurrences of substring sub in
        string S[start:end].  Optional arguments start and end are
        interpreted as in slice notation.
        """
        return 0

View Code

譬如

图片 42图片 43

flag = 'aaababbcccaddadaddd'
print(flag.count('a'))
print(flag.count('a',0,3))
#运行结果
7
3

View Code

.encode()

编码,在python3中,str暗中认可是unicode数据类型,能够将其编码成bytes数据

图片 44图片 45

    def encode(self, encoding='utf-8', errors='strict'): # real signature unknown; restored from __doc__
        """
        S.encode(encoding='utf-8', errors='strict') -> bytes

        Encode S using the codec registered for encoding. Default encoding
        is 'utf-8'. errors may be given to set a different error
        handling scheme. Default is 'strict' meaning that encoding errors raise
        a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
        'xmlcharrefreplace' as well as any other name registered with
        codecs.register_error that can handle UnicodeEncodeErrors.
        """
        return b""

View Code

例如

图片 46图片 47

flag = 'aaababbcccaddadaddd'
print(flag.encode('utf8'))
#运行结果
b'aaababbcccaddadaddd'

View Code

.endswith()

判别字符串结尾是不是是有个别字符串和字符,能够经过索引钦赐范围

图片 48图片 49

   def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.endswith(suffix[, start[, end]]) -> bool

        Return True if S ends with the specified suffix, False otherwise.
        With optional start, test S beginning at that position.
        With optional end, stop comparing S at that position.
        suffix can also be a tuple of strings to try.
        """
        return False

View Code

举个例证

图片 50图片 51

flag = 'aaababbcccaddadaddd'
print(flag.endswith('aa'))
print(flag.endswith('ddd'))
print(flag.endswith('dddd'))
print(flag.endswith('aaa',0,3))
print(flag.endswith('aaa',0,2))
#运行结果
False
True
False
True
False

View Code

.expandtabs()

把制表符tab("t"卡塔尔转变为空格

图片 52图片 53

  def expandtabs(self, tabsize=8): # real signature unknown; restored from __doc__
        """
        S.expandtabs(tabsize=8) -> str

        Return a copy of S where all tab characters are expanded using spaces.
        If tabsize is not given, a tab size of 8 characters is assumed.
        """
        return ""

View Code

举个例证

图片 54图片 55

flag = "thello python!"
print(flag)
print(flag.expandtabs())   #默认tabsize=8
print(flag.expandtabs(20))
#运行结果
    hello python!             #一个tab,长度为4个空格
        hello python!         #8个空格
                    hello python!    #20个空格

View Code

.find()

检索字符,再次回到索引值,能够因而点名索引范围内寻觅,查找不到重临-1

图片 56图片 57

    def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.find(sub[, start[, end]]) -> int

        Return the lowest index in S where substring sub is found,
        such that sub is contained within S[start:end].  Optional
        arguments start and end are interpreted as in slice notation.

        Return -1 on failure.
        """
        return 0

View Code

举个例证

图片 58图片 59

flag = "hello python!"
print(flag.find('e'))
print(flag.find('a'))
print(flag.find('h',4,-1))
#运行结果
1
-1
9

View Code

.format()

格式化输出,使用"{}"符号作为操作符。

图片 60图片 61

def format(self, *args, **kwargs): # known special case of str.format
        """
        S.format(*args, **kwargs) -> str

        Return a formatted version of S, using substitutions from args and kwargs.
        The substitutions are identified by braces ('{' and '}').
        """
        pass

View Code

举个例证

图片 62图片 63

#位置参数
flag = "hello {0} and {1}!"
print(flag.format('python','php'))
flag = "hello {} and {}!"
print(flag.format('python','php'))
#变量参数
flag = "{name} is {age} years old!"
print(flag.format(name='Frank',age = 23))
#结合列表
infor=["Frank",23]
print("{0[0]} is {0[1]} years old".format(infor))
#运行结果
hello python and php!
hello python and php!
Frank is 23 years old!
Frank is 23 years old

View Code

.format_map()

格式化输出

图片 64图片 65

 def format_map(self, mapping): # real signature unknown; restored from __doc__
        """
        S.format_map(mapping) -> str

        Return a formatted version of S, using substitutions from mapping.
        The substitutions are identified by braces ('{' and '}').
        """
        return ""

View Code

例如

图片 66图片 67

people={
    'name':['Frank','Caroline'],
    'age':['23','22'],
}
print("My name is {name[0]},i am {age[1]} years old !".format_map(people))
#运行结果
My name is Frank,i am 22 years old !

View Code

.index()

凭仗字符查找索引值,能够内定索引范围查找,查找不到位报错

图片 68图片 69

 def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.index(sub[, start[, end]]) -> int

        Like S.find() but raise ValueError when the substring is not found.
        """
        return 0

View Code

比如

图片 70图片 71

flag = "hello python!"
print(flag.index("e"))
print(flag.index("o",6,-1))
#运行结果
1
10

View Code

.isalnum()

认清是不是是字母或数字构成,重回布尔值

图片 72图片 73

def isalnum(self): # real signature unknown; restored from __doc__
        """
        S.isalnum() -> bool

        Return True if all characters in S are alphanumeric
        and there is at least one character in S, False otherwise.
        """
        return False

View Code

比如

图片 74图片 75

flag = "hellopython"
flag1 = "hellopython22"
flag2 = "hellopython!!"
flag3 = "!@#!#@!!@"
print(flag.isalnum())
print(flag1.isalnum())
print(flag2.isalnum())
print(flag3.isalnum())
#运行结果
True
True
False
False

View Code

.isalpha()

认清是不是是字母组合,重返布尔值

图片 76图片 77

 def isalpha(self): # real signature unknown; restored from __doc__
        """
        S.isalpha() -> bool

        Return True if all characters in S are alphabetic
        and there is at least one character in S, False otherwise.
        """
        return False

View Code

比方

图片 78图片 79

flag = "hellopython"
flag1 = "hellopython22"
print(flag.isalpha())
print(flag1.isalpha())
#运行结果
True
False

View Code

.isdecimal()

认清是还是不是是二个十进制正整数,再次来到布尔值

图片 80图片 81

  def isdecimal(self): # real signature unknown; restored from __doc__
        """
        S.isdecimal() -> bool

        Return True if there are only decimal characters in S,
        False otherwise.
        """
        return False

View Code

举个例证

图片 82图片 83

number = "1.2"
number1 = "12"
number2 = "-12"
number3 = "1222"
print(number.isdecimal())
print(number1.isdecimal())
print(number2.isdecimal())
print(number3.isdecimal())
#运行结果
False
True
False
True

View Code

isdigit()

认清是或不是是一个正整数,再次回到布尔值,与地方isdecimal相通

图片 84图片 85

  def isdigit(self): # real signature unknown; restored from __doc__
        """
        S.isdigit() -> bool

        Return True if all characters in S are digits
        and there is at least one character in S, False otherwise.
        """
        return False

View Code

举个例证

图片 86图片 87

number = "1.2"
number1 = "12"
number2 = "-12"
number3 = "11"
print(number.isdigit())
print(number1.isdigit())
print(number2.isdigit())
print(number3.isdigit())
#运行结果
False
True
False
True

View Code

.isidentifier()

看清是或不是为python中的标记符

图片 88图片 89

 def isidentifier(self): # real signature unknown; restored from __doc__
        """
        S.isidentifier() -> bool

        Return True if S is a valid identifier according
        to the language definition.

        Use keyword.iskeyword() to test for reserved identifiers
        such as "def" and "class".
        """
        return False

View Code

举个例证

图片 90图片 91

flag = "cisco"
flag1 = "1cisco"
flag2 = "print"
print(flag.isidentifier())
print(flag1.isidentifier())
print(flag2.isidentifier())
#运行结果
True
False
True

View Code

.islower()

 判定字符串中的字母是或不是都是小写,再次来到布尔值

图片 92图片 93

    def islower(self): # real signature unknown; restored from __doc__
        """
        S.islower() -> bool

        Return True if all cased characters in S are lowercase and there is
        at least one cased character in S, False otherwise.
        """
        return False

View Code

比如

图片 94图片 95

flag = "cisco"
flag1 = "cisco222"
flag2 = "Cisco"
print(flag.islower())
print(flag1.islower())
print(flag2.islower())
#运行结果
True
True
False

View Code

.isnumeric()

判别是或不是为数字,那一个很苍劲,普通话字符,繁体字数字都足以识别

图片 96图片 97

 def isnumeric(self): # real signature unknown; restored from __doc__
        """
        S.isnumeric() -> bool

        Return True if there are only numeric characters in S,
        False otherwise.
        """
        return False

View Code

比如

图片 98图片 99

number = "123"
number1 = "一"
number2 = "壹"
number3 = "123q"
number4 = "1.1"
print(number.isnumeric())
print(number1.isnumeric())
print(number2.isnumeric())
print(number3.isnumeric())
print(number4.isnumeric())
#运行结果
True
True
True
False
False

View Code

.isprintable()

认清引号里面的是还是不是皆以可打字与印刷的,重临布尔值

图片 100图片 101

   def isprintable(self): # real signature unknown; restored from __doc__
        """
        S.isprintable() -> bool

        Return True if all characters in S are considered
        printable in repr() or S is empty, False otherwise.
        """
        return False

View Code

举个例证

图片 102图片 103

flag = "n123"
flag1 = "t"
flag2 = "123"
flag3 = r"n123"    # r 可以是转义字符失效
print(flag.isprintable())     #n不可打印
print(flag1.isprintable())    #t不可打印
print(flag2.isprintable())
print(flag3.isprintable())
#运行结果
False
False
True
True

View Code

.isspace()

看清字符串里面都是徒手位,空格大概tab,再次来到布尔值

图片 104图片 105

  def isspace(self): # real signature unknown; restored from __doc__
        """
        S.isspace() -> bool

        Return True if all characters in S are whitespace
        and there is at least one character in S, False otherwise.
        """
        return False

View Code

比如

图片 106图片 107

flag = '    '     #4个空格
flag1 = '        '#2个tab
print(flag.isspace())
print(flag1.isspace())
#运行结果
True
True

View Code

.istitle()

决断字符串里面包车型客车字符是否都以大写起先,再次来到布尔值

图片 108图片 109

  def isspace(self): # real signature unknown; restored from __doc__
        """
        S.isspace() -> bool

        Return True if all characters in S are whitespace
        and there is at least one character in S, False otherwise.
        """
        return False

View Code

举个例证

图片 110图片 111

flag = "Welcome Frank"
flag1 = "Welcome frank"
print(flag.istitle())
print(flag1.istitle())
#运行结果
True
False

View Code

.isupper()

推断是不是都以字符串里的假名都以大写

图片 112图片 113

    def isupper(self): # real signature unknown; restored from __doc__
        """
        S.isupper() -> bool

        Return True if all cased characters in S are uppercase and there is
        at least one cased character in S, False otherwise.
        """
        return False

View Code

比如

图片 114图片 115

flag = "WELCOME1"
flag1 = "Welcome1"
print(flag.isupper())
print(flag1.isupper())
#运行结果
True
False

View Code

.join()

将字符串以内定的字符连接生成贰个新的字符串

图片 116图片 117

  def join(self, iterable): # real signature unknown; restored from __doc__
        """
        S.join(iterable) -> str

        Return a string which is the concatenation of the strings in the
        iterable.  The separator between elements is S.
        """
        return ""

View Code

譬喻

图片 118图片 119

flag = "welcome"
print("#".join(flag))
#运行结果
w#e#l#c#o#m#e

View Code

.ljust()

左对齐,可钦定字符宽度和填充字符

图片 120图片 121

   def ljust(self, width, fillchar=None): # real signature unknown; restored from __doc__
        """
        S.ljust(width[, fillchar]) -> str

        Return S left-justified in a Unicode string of length width. Padding is
        done using the specified fill character (default is a space).
        """
        return ""

View Code

举个例证

图片 122图片 123

flag = "welcome"
print(flag.ljust(20,"*"))
#运行结果
welcome*************

View Code

.rjust()

右对齐,可钦命字符宽度和填充字符

图片 124图片 125

    def rjust(self, width, fillchar=None): # real signature unknown; restored from __doc__
        """
        S.rjust(width[, fillchar]) -> str

        Return S right-justified in a string of length width. Padding is
        done using the specified fill character (default is a space).
        """
        return ""

View Code

举个例证

图片 126图片 127

flag = "welcome"
print(flag.rjust(20,"*"))
#运行结果
*************welcome

View Code

.lower()

对字符串里的具备字母转小写

图片 128图片 129

    def lower(self): # real signature unknown; restored from __doc__
        """
        S.lower() -> str

        Return a copy of the string S converted to lowercase.
        """
        return ""

View Code

举个例证

图片 130图片 131

flag = "WELcome"
#运行结果
welcome

View Code

.upper()

对字符串里的持有字母转大写

图片 132图片 133

    def upper(self): # real signature unknown; restored from __doc__
        """
        S.upper() -> str

        Return a copy of S converted to uppercase.
        """
        return ""

View Code

举个例证

图片 134图片 135

flag = "WELcome"
print(flag.upper())
#运行结果
WELCOME

View Code

.title()

对字符串里的单词举办首字母大写调换

图片 136图片 137

    def title(self): # real signature unknown; restored from __doc__
        """
        S.title() -> str

        Return a titlecased version of S, i.e. words start with title case
        characters, all remaining cased characters have lower case.
        """
        return ""

View Code

比如

图片 138图片 139

flag = "welcome frank"
print(flag.title())
#运行结果
Welcome Frank

View Code

.lstrip()

暗中同意去除侧面空白字符,可钦赐去除的字符,去除钦命的字符后,会被空白占位。

图片 140图片 141

  def lstrip(self, chars=None): # real signature unknown; restored from __doc__
        """
        S.lstrip([chars]) -> str

        Return a copy of the string S with leading whitespace removed.
        If chars is given and not None, remove characters in chars instead.
        """
        return ""

View Code

比方

图片 142图片 143

flag = "     welcome frank"
flag1 = "@@@@welcome frank"
print(flag.lstrip())
print(flag.lstrip("@"))
print(flag.lstrip("@").lstrip())
#运行结果
welcome frank
     welcome frank
welcome frank

View Code

.rstrip()

私下认可去除侧边空白字符,可钦点去除的字符,去除钦命的字符后,会被空白占位。

图片 144图片 145

 def rstrip(self, chars=None): # real signature unknown; restored from __doc__
        """
        S.rstrip([chars]) -> str

        Return a copy of the string S with trailing whitespace removed.
        If chars is given and not None, remove characters in chars instead.
        """
        return ""

View Code

比方

图片 146图片 147

flag = "welcome frank    "
flag1 = "welcome frank@@@@"
# print(flag.title())
print(flag.rstrip())
print(flag.rstrip("@"))
print(flag.rstrip("@").rstrip())
#运行结果
welcome frank
welcome frank    #右边有4个空格
welcome frank

View Code

.strip()

私下认可去除两侧空白字符,可钦点去除的字符,去除钦定的字符后,会被空白占位。

图片 148图片 149

    def strip(self, chars=None): # real signature unknown; restored from __doc__
        """
        S.strip([chars]) -> str

        Return a copy of the string S with leading and trailing
        whitespace removed.
        If chars is given and not None, remove characters in chars instead.
        """
        return ""

View Code

比如

图片 150图片 151

flag = "    welcome frank    "
flag1 = "@@@@welcome frank@@@@"
# print(flag.title())
print(flag.strip())
print(flag.strip("@"))
print(flag.strip("@").strip())
#运行结果
welcome frank
    welcome frank    #右边有4个空格
welcome frank

View Code

.maketrans()和translate()

始建字符映射的转变表,对于收受三个参数的最简易的调用方式,第多少个参数是字符串,表示须求改换的字符,第二个参数也是字符串表示转换的对象。多少个字符串的长度必得风流倜傥律,为顺序对应的涉及。

图片 152图片 153

   def maketrans(self, *args, **kwargs): # real signature unknown
        """
        Return a translation table usable for str.translate().

        If there is only one argument, it must be a dictionary mapping Unicode
        ordinals (integers) or characters to Unicode ordinals, strings or None.
        Character keys will be then converted to ordinals.
        If there are two arguments, they must be strings of equal length, and
        in the resulting dictionary, each character in x will be mapped to the
        character at the same position in y. If there is a third argument, it
        must be a string, whose characters will be mapped to None in the result.
        """
        pass

View Code

图片 154图片 155

  def translate(self, table): # real signature unknown; restored from __doc__
        """
        S.translate(table) -> str

        Return a copy of the string S in which each character has been mapped
        through the given translation table. The table must implement
        lookup/indexing via __getitem__, for instance a dictionary or list,
        mapping Unicode ordinals to Unicode ordinals, strings, or None. If
        this operation raises LookupError, the character is left untouched.
        Characters mapped to None are deleted.
        """
        return ""

View Code

举个例证

图片 156图片 157

intab = "aeiou"
outtab = "12345"
trantab = str.maketrans(intab, outtab)
str = "this is string example....wow!!!"
print (str.translate(trantab))
#运行结果
th3s 3s str3ng 2x1mpl2....w4w!!!

View Code

.partition()

以钦赐字符分割,重返叁个元组

图片 158图片 159

 def partition(self, sep): # real signature unknown; restored from __doc__
        """
        S.partition(sep) -> (head, sep, tail)

        Search for the separator sep in S, and return the part before it,
        the separator itself, and the part after it.  If the separator is not
        found, return S and two empty strings.
        """
        pass

View Code

举个例证

图片 160图片 161

flag = "welcome"
print(flag.partition("e"))
#运行结果
('w', 'e', 'lcome')

View Code

.replace()

将内定的字符替换为新的字符,可钦点替换的个数

图片 162图片 163

    def replace(self, old, new, count=None): # real signature unknown; restored from __doc__
        """
        S.replace(old, new[, count]) -> str

        Return a copy of S with all occurrences of substring
        old replaced by new.  If the optional argument count is
        given, only the first count occurrences are replaced.
        """
        return ""

View Code

举个例子

图片 164图片 165

flag = "welcome frank ,e.."
print(flag.replace("e","z"))
print(flag.replace("e","z",1))
#运行结果
wzlcomz frank ,z..
wzlcome frank ,e..

View Code

.rfind()

再次回到字符串第三次现身的职位,从右向左差,重回索引值,若未有,则赶回-1,可凭仗目录范围查找

图片 166图片 167

   def rfind(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.rfind(sub[, start[, end]]) -> int

        Return the highest index in S where substring sub is found,
        such that sub is contained within S[start:end].  Optional
        arguments start and end are interpreted as in slice notation.

        Return -1 on failure.
        """
        return 0

View Code

比方

图片 168图片 169

flag = "welcome frank ,e.."
print(flag.rfind("e"))
print(flag.rfind("x"))
print(flag.rfind("e",0,3))
#运行结果
15
-1
1

View Code

.rindex()

 查找字符索引值,从右向左,再次回到索引值,与rfind肖似,查找不到位报错

图片 170图片 171

 def rindex(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.rindex(sub[, start[, end]]) -> int

        Like S.rfind() but raise ValueError when the substring is not found.
        """
        return 0

View Code

举例

图片 172图片 173

flag = "welcome frank ,e.."
print(flag.rindex("e"))
print(flag.rindex("e",0,3))
#运行结果
15
1

View Code

.rpartition()

以钦命字符从右向左分割,只分割三次,再次来到元组,若未有一点名的字符,则在回去的元组前面加几个空字符串

图片 174图片 175

    def rpartition(self, sep): # real signature unknown; restored from __doc__
        """
        S.rpartition(sep) -> (head, sep, tail)

        Search for the separator sep in S, starting at the end of S, and return
        the part before it, the separator itself, and the part after it.  If the
        separator is not found, return two empty strings and S.
        """
        pass

View Code

举个例证

图片 176图片 177

flag = "welcome frank ,e.."
print(flag.rpartition("e"))
print(flag.rpartition("x"))
#运行结果
('welcome frank ,', 'e', '..')
('', '', 'welcome frank ,e..')

View Code

.split()

分开,能够以钦命的字符分割,可钦赐分割的次数,暗中认可从左向右分割,与partition不一致的是,split分割后会删除钦命的字符,默认以空格为分割符,重返元组。

图片 178图片 179

    def split(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
        """
        S.split(sep=None, maxsplit=-1) -> list of strings

        Return a list of the words in S, using sep as the
        delimiter string.  If maxsplit is given, at most maxsplit
        splits are done. If sep is not specified or is None, any
        whitespace string is a separator and empty strings are
        removed from the result.
        """
        return []

View Code

举例

图片 180图片 181

flag = "welcome frank, e.."
print(flag.split())
print(flag.split('e'))
print(flag.split('e',1))
#运行结果
['welcome', 'frank,', 'e..']
['w', 'lcom', ' frank, ', '..']
['w', 'lcome frank, e..']

View Code

.rsplit()

与split相通,只是它是从右向左分

图片 182图片 183

    def rsplit(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
        """
        S.rsplit(sep=None, maxsplit=-1) -> list of strings

        Return a list of the words in S, using sep as the
        delimiter string, starting at the end of the string and
        working to the front.  If maxsplit is given, at most maxsplit
        splits are done. If sep is not specified, any whitespace string
        is a separator.
        """
        return []

View Code

比方

图片 184图片 185

flag = "welcome frank, e.."
print(flag.rsplit())
print(flag.rsplit('e'))
print(flag.rsplit('e',1))
#运行结果
['welcome', 'frank,', 'e..']
['w', 'lcom', ' frank, ', '..']
['welcome frank, ', '..']

View Code

.splitlines()

字符串转换为列表

图片 186图片 187

    def splitlines(self, keepends=None): # real signature unknown; restored from __doc__
        """
        S.splitlines([keepends]) -> list of strings

        Return a list of the lines in S, breaking at line boundaries.
        Line breaks are not included in the resulting list unless keepends
        is given and true.
        """
        return []

View Code

举个例子

图片 188图片 189

info = "hello,my name is Frank"
print(info.splitlines())
#运行结果
['hello,my name is Frank']

View Code

.startswith()

剖断是不是以钦命字符串或字符最早,可钦命索引范围,重返布尔值

图片 190图片 191

 def startswith(self, prefix, start=None, end=None): # real signature unknown; restored from __doc__
        """
        S.startswith(prefix[, start[, end]]) -> bool

        Return True if S starts with the specified prefix, False otherwise.
        With optional start, test S beginning at that position.
        With optional end, stop comparing S at that position.
        prefix can also be a tuple of strings to try.
        """
        return False

View Code

举个例证

图片 192图片 193

info = "hello,my name is Frank"
print(info.startswith("he"))
print(info.startswith("e"))
print(info.startswith("m",6,-1))
#运行结果
True
False
True

View Code

.swapcase()

将字符串中的大小写交换

图片 194图片 195

   def swapcase(self): # real signature unknown; restored from __doc__
        """
        S.swapcase() -> str

        Return a copy of S with uppercase characters converted to lowercase
        and vice versa.
        """
        return ""

View Code

举个例证

图片 196图片 197

info = "Hello,My name is Frank"
print(info.swapcase())
#运行结果
hELLO,mY NAME IS fRANK

View Code

.zfill()

钦赐字符串宽度,不足的动手填“0”

图片 198图片 199

    def zfill(self, width): # real signature unknown; restored from __doc__
        """
        S.zfill(width) -> str

        Pad a numeric string S with zeros on the left, to fill a field
        of the specified width. The string S is never truncated.
        """
        return ""

View Code

比如

图片 200图片 201

info = "Hello,My name is Frank"
print(info.zfill(50))
#运行结果
0000000000000000000000000000Hello,My name is Frank

View Code

 

简历类(Resume) :世襲于系统的克隆接口(ICloneable)

点击源码上的复制按钮还是能直接将源代码复制下来。

 2.angular.bootstrap()

四、列表

列表是由风流浪漫连串按一定顺序排列的因素结合。在python中,用方括号([]),来表示列表,并用逗号来划分个中的成分,大家来看一下轻易的列表,其type为"list"

图片 202图片 203

name = ['Frank','Caroline','Bob','Saber']
print(name)  #直接打印会将中括号、引号和逗号都打印出来
print(name[1]) #添加索引可打印对应的值,从索引值从0开始
print(name[-1]) #打印最后一个元素
print(name[0:2]) #用冒号来切片,取右不取左
print(name[-2:]) #冒号右边不写代表一直打印到最后一个
print(name[:1]) #冒号左边不写代表从第“0”个开始打印

View Code

 恒河沙数方法如下:

.index()

 查找对应成分的索引值,重回索引值,能够内定索引范围来搜寻,查找不到场报错

图片 204图片 205

    def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
        """
        L.index(value, [start, [stop]]) -> integer -- return first index of value.
        Raises ValueError if the value is not present.
        """
        return 0

View Code

 举个例证

图片 206图片 207

name = ['Frank','Caroline','Bob','Saber']
print(name.index("Frank"))
print(name.index("Bob",1,-1))
#运行结果
0
2

View Code

.count()

 总结某些成分的个数

图片 208图片 209

  def count(self, value): # real signature unknown; restored from __doc__
        """ L.count(value) -> integer -- return number of occurrences of value """
        return 0

View Code

 举个例证

图片 210图片 211

name = ['Frank','Caroline','Bob','Saber','Frank']
print(name.count('Frank'))
#运行结果
2

View Code

 .append()

 在列表的尾声添美金素

图片 212图片 213

    def append(self, p_object): # real signature unknown; restored from __doc__
        """ L.append(object) -> None -- append object to end """
        pass

View Code

 举个例证

图片 214图片 215

name = ['Frank','Caroline','Bob','Saber','Frank']
name.append('Mei')
print(name)
#运行结果
['Frank', 'Caroline', 'Bob', 'Saber', 'Frank', 'Mei']

View Code

.clear()

 清空驶列车表

图片 216图片 217

 def clear(self): # real signature unknown; restored from __doc__
        """ L.clear() -> None -- remove all items from L """
        pass

View Code

 比如

图片 218图片 219

name = ['Frank','Caroline','Bob','Saber','Frank']
name.clear()
print(name)
#运行结果
[]

View Code

 .copy()

 复制列表

图片 220图片 221

   def copy(self): # real signature unknown; restored from __doc__
        """ L.copy() -> list -- a shallow copy of L """
        return []

View Code

 举个例证

图片 222图片 223

name = ['Saber','Frank',1,2,[3,4]]
name_cp = name.copy()
print(name_cp)
name[0]='Tom'
name[3]='7'
name[4][0]='8'
print(name)
print(name_cp)
#运行结果
['Saber', 'Frank', 1, 2, [3, 4]]
['Tom', 'Frank', 1, '7', ['8', 4]]
['Saber', 'Frank', 1, 2, ['8', 4]]

View Code

大家会发掘,大家给name[0]、name[3]、和name[4][0]都重新赋值了,为啥小编再一次赋值的name[4][0]会影响到自个儿复制的列表的啊?

率先我们来看一下以此复制图解:

 图片 224

大家在复制的时候,新复制的列表都会指向被复制列表的地址空间,name[4]和name_cp[4]小编也是个列表,它们照准的是同二个列表地址空间。大家来看一下给name列表重新赋值后,地址空间的变化:

 图片 225

 重新赋值后,内部存储器给name[3]、name[0]、name[4][0]都重复开荒了一块内存空间,name[0]本着了内部存款和储蓄器地址38703432,name[3]本着了内部存款和储蓄器地址1400943960,而name[4]可能指向37092936,可是内存地址37092936指向name[4][0]内部存款和储蓄器地址爆发了扭转,指向了1400944350,所以,在列表中的列表大家给它再度赋值的时候,也会改良复制列表的值,因为它们的列表里的列表都以指向同一块地点空间。那么只要我们想全盘复制怎么做呢?

 能够调用函数deepcopy(卡塔尔(英语:State of Qatar).

图片 226图片 227

import copy
name = ['Saber','Frank',1,2,[3,4]]
name_cp=copy.deepcopy(name)
name[4][0]=5
print(name)
print(name_cp)
#运行结果
['Saber', 'Frank', 1, 2, [5, 4]]
['Saber', 'Frank', 1, 2, [3, 4]]

View Code

 图片 228

 那样会给复制后的列表中的列表重新开荒八个地点空间,然后指向列表中列表的因素的地方空间,那样您怎么转移原列表name,name_copy都不会变动。

.extend()

 函数用于在列表末尾一遍性追加另二个队列中的多少个值(用新列表扩大原本的列表)。

图片 229图片 230

 def extend(self, iterable): # real signature unknown; restored from __doc__
        """ L.extend(iterable) -> None -- extend list by appending elements from the iterable """
        pass

View Code

 举个例子

图片 231图片 232

name = ['Saber','Frank']
nameto = ['Mei','Jack']
name.extend(nameto)
print(name)
#运行结果
['Saber', 'Frank', 'Mei', 'Jack']

View Code

insert()

安顿成分,要求钦命索引值来插入

图片 233图片 234

 def insert(self, index, p_object): # real signature unknown; restored from __doc__
        """ L.insert(index, object) -- insert object before index """
        pass

View Code

 举例

图片 235图片 236

name = ['Saber','Frank']
name.insert(0,'Jack')
print(name)
#运行结果
['Jack', 'Saber', 'Frank']

View Code

 .pop()

 弹出成分,暗中认可弹出最终三个因素,能够内定索引,弹出相应的要素,当列表弹空大概尚未点名的索引值会报错,并回到弹出的值

图片 237图片 238

 def pop(self, index=None): # real signature unknown; restored from __doc__
        """
        L.pop([index]) -> item -- remove and return item at index (default last).
        Raises IndexError if list is empty or index is out of range.
        """
        pass

View Code

举例

图片 239图片 240

name = ['Saber','Frank','Caroline','Jack']
name.pop()
print(name)
name = ['Saber','Frank','Caroline','Jack']
name.pop(1)
print(name)
#运行结果
['Saber', 'Frank', 'Caroline']
['Saber', 'Caroline', 'Jack']

View Code

.remove()

移除钦点的要素

图片 241图片 242

def remove(self, value): # real signature unknown; restored from __doc__
        """
        L.remove(value) -> None -- remove first occurrence of value.
        Raises ValueError if the value is not present.
        """
        pass

View Code

 举个例证

图片 243图片 244

name = ['Saber','Frank','Caroline','Jack']
name.remove('Frank')
print(name)
#运行结果
['Saber', 'Caroline', 'Jack']

View Code

.reverse()

 列表反转,恒久改正

图片 245图片 246

    def reverse(self): # real signature unknown; restored from __doc__
        """ L.reverse() -- reverse *IN PLACE* """
        pass

View Code

 举个例证

图片 247图片 248

name = ['Saber','Frank','Caroline','Jack']
name.reverse()
print(name)
#运行结果
['Jack', 'Caroline', 'Frank', 'Saber']

View Code

.sort()

对列表进行排序,永远修正,假使列表中还要设有分歧门类的多少,则不能排序,举个例子含有整型和字符串,传递reverse=True能够倒着排序。

图片 249图片 250

 def sort(self, key=None, reverse=False): # real signature unknown; restored from __doc__
        """ L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE* """
        pass

View Code

举个例证

图片 251图片 252

name = ['Saber','Frank','Caroline','Jack','1','abc','xyz']
name.sort()
print(name)
name.sort(reverse=True)
print(name)
#运行结果
['1', 'Caroline', 'Frank', 'Jack', 'Saber', 'abc', 'xyz']
['xyz', 'abc', 'Saber', 'Jack', 'Frank', 'Caroline', '1']
number = [1,2,3,42,12,32,43,543]
number.sort()
print(number)
number.sort(reverse=True)
print(number)
#运行结果
[1, 2, 3, 12, 32, 42, 43, 543]
[543, 43, 42, 32, 12, 3, 2, 1]

View Code

 

图片 253图片 254

 

图片 255图片 256

五、元组

元组和列表相像,不一致的是元组的因素是不能够改改的,使用小括号"(卡塔尔(英语:State of Qatar)"括起来,用逗号","分开,其type为tuple

图片 257图片 258

number = (1,2,2,2,1)
print(type(number))
print(number[0])
print(number[-1])
print(number[1:])
#运行结果
<class 'tuple'>
1
1
(2, 2, 2, 1)

View Code

大范围方式如下:

.count()

算算内定成分的个数

图片 259图片 260

   def count(self, value): # real signature unknown; restored from __doc__
        """ T.count(value) -> integer -- return number of occurrences of value """
        return 0

View Code

举个例证

图片 261图片 262

number = (1,2,2,2,1)
print(number.count(2))
#运行结果
3

View Code

.index()

招来钦命元素的目录,能够指定索引范围来查找

图片 263图片 264

 def index(self, value, start=None, stop=None): # real signature unknown; restored from __doc__
        """
        T.index(value, [start, [stop]]) -> integer -- return first index of value.
        Raises ValueError if the value is not present.
        """
        return 0

View Code

比方

图片 265图片 266

number = (1,2,2,2,1)
print(number.index(2))
print(number.index(2,2,-1))
#运行结果
1
2

View Code

 

namespace Ptototype_Pattern
{
    class ReSume:ICloneable
    {
        private string name;
        private string age;
        private string sex;
        private string birthday;
        private string time;
        private string company;
        public ReSume(string name)
        {
            this.name = name;
        }

        /// <summary>
        /// 设置个人信息
        /// </summary>
        /// <param name="age"></param>
        /// <param name="sex"></param>
        /// <param name="birthday"></param>
        public void SetPersonInfo(string age, string sex, string birthday)
        {
            this.age = age;
            this.sex = sex;
            this.birthday = birthday;
        }

        /// <summary>
        /// 设置工作经历
        /// </summary>
        /// <param name="time"></param>
        /// <param name="company"></param>
        public void SetWorkExperice(string time, string company)
        {
            this.time = time;
            this.company = company;
        }

        public void Display()
        {
            Console.WriteLine("姓名:{0}  年龄:{1} 出生日期:{2}", name, age, birthday);
            Console.WriteLine("在 {0} 工作于 {1} n",time,company);
        }

        public Object Clone()
        {
            return (Object)this.MemberwiseClone();
        }
    }
}

 

<!DOCTYPE HTML>
<meta charset="utf-8">
<head>
</head>
<script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>
</body>
<script>
    //   angular.bootstrap(); 手动加载模块,   模仿 ng-app自动加载模块    注意不能出现  ng-app
    //创建模块1
  var module1=angular.module('module1',[]);
    module1.controller('controller1', function ($scope) {
        $scope.name='haha';
    })
    //创建模块2
  var module2=angular.module('module2',[]);
  module2.controller('controller2', function ($scope) {
      $scope.name='hehe';
  })
    // 页面加载完成后再加载模块
    angular.element(document).ready(function () {
        angular.bootstrap(document.getElementById("div1"),["module1"]);    //  div1加载 模块1
        angular.bootstrap(document.getElementById("div2"),["module2"]);
    })
</script>
<div id="div1" ng-controller="controller1">div1: {{name}}</div>   <!--  这里要有控制器 -->
<div id="div2" ng-controller="controller2">div2: {{name}}</div>
</body>
</meta>

六、集合

会见是一文山会海冬天的成分结合,全部你不能够使用索引值,在打字与印刷的时候,元组是理所必然排序,天然去重的,其type为set

图片 267图片 268

number = {1,2,3,4,4,5,6}
number1 = {1,6,2,1,8,9,10}
print(number)
print(number1)
#运行结果
{1, 2, 3, 4, 5, 6}
{1, 2, 6, 8, 9, 10}

View Code

常用方法如下

.remove()

移除钦赐的因素

图片 269图片 270

  def remove(self, *args, **kwargs): # real signature unknown
        """
        Remove an element from a set; it must be a member.

        If the element is not a member, raise a KeyError.
        """
        pass

View Code

比如

图片 271图片 272

number = {1,2,3,4,4,5,6}
print(number)
number.remove(1)
print(number)
#运行结果
{1, 2, 3, 4, 5, 6}
{2, 3, 4, 5, 6}

View Code

.pop()

弹出排序过后的率先个要素

图片 273图片 274

    def pop(self, *args, **kwargs): # real signature unknown
        """
        Remove and return an arbitrary set element.
        Raises KeyError if the set is empty.
        """
        pass

View Code

 

举个例证

图片 275图片 276

number = {1,2,3,4,4,5,6}
print(number)
number_pop = number.pop()
print(number_pop)
print(number)
#运行结果
{1, 2, 3, 4, 5, 6}
1
{2, 3, 4, 5, 6}

View Code

.clear()

清空驶列车表重临set(卡塔尔(قطر‎

图片 277图片 278

    def clear(self, *args, **kwargs): # real signature unknown
        """ Remove all elements from this set. """
        pass

View Code

比如

图片 279图片 280

number = {1,2,3,4,4,5,6}
print(number)
number.clear()
print(number)
#运行结果
{1, 2, 3, 4, 5, 6}
set()

View Code

.copy()

复制群集

图片 281图片 282

   def copy(self, *args, **kwargs): # real signature unknown
        """ Return a shallow copy of a set. """
        pass

View Code

举例

图片 283图片 284

number = {1,2,3,4,4,5,6}
print(number)
number2 = number.copy()
number.pop()
print(number)
print(number2)
#运行结果
{1, 2, 3, 4, 5, 6}
{2, 3, 4, 5, 6}
{1, 2, 3, 4, 5, 6}

View Code

.add()

添英镑素

图片 285图片 286

    def add(self, *args, **kwargs): # real signature unknown
        """
        Add an element to a set.

        This has no effect if the element is already present.
        """
        pass

View Code

举个例证

图片 287图片 288

number = {1,2,3,4,4,5,6}
print(number)
number.add(7)
print(number)
#运行结果
{1, 2, 3, 4, 5, 6}
{1, 2, 3, 4, 5, 6, 7}

View Code

.difference()

求差集,可以用“-”代替

图片 289图片 290

    def difference(self, *args, **kwargs): # real signature unknown
        """
        Return the difference of two or more sets as a new set.

        (i.e. all elements that are in this set but not the others.)
        """
        pass

View Code

举个例证

图片 291图片 292

number = {1,2,3,4,5,6,8,9}
number1 = {2,3,8,9,11,12,10}
print(number.difference(number1))
print(number1.difference(number))
print(number - number1)
print(number1 - number)
##运行结果
{1, 4, 5, 6}
{10, 11, 12}
{1, 4, 5, 6}
{10, 11, 12}

View Code

.union()

求并集,可用“|”代替

图片 293图片 294

    def union(self, *args, **kwargs): # real signature unknown
        """
        Return the union of sets as a new set.

        (i.e. all elements that are in either set.)
        """
        pass

View Code

比方

图片 295图片 296

number = {1,2,3,4,5,6,8,9}
number1 = {2,3,8,9,11,12,10}
print(number.union(number1))
print(number | number1)
#运行结果
{1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12}
{1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12}

View Code

difference_update.()

分裂更新,没有再次来到值,直接改动群集

图片 297图片 298

    def difference_update(self, *args, **kwargs): # real signature unknown
        """ Remove all elements of another set from this set. """
        pass

View Code

举个例证

图片 299图片 300

number = {1,2,3,4,5,6,8,9,13}
number1 = {2,3,8,9,11,12,10}
number.difference_update(number1)
print(number)
#运行结果
{1, 4, 5, 6, 13}

View Code

.discard()

 移除内定成分,假使群集内未有一点名的因素,就怎么着都不做

图片 301图片 302

    def discard(self, *args, **kwargs): # real signature unknown
        """
        Remove an element from a set if it is a member.

        If the element is not a member, do nothing.
        """
        pass

View Code

举个例证

图片 303图片 304

number = {1,2,3,4,5,6,8,9,13}
number.discard(1)
print(number)
#运行结果
{2, 3, 4, 5, 6, 8, 9, 13}

View Code

.intersection()

交集,可以用"&"代替

图片 305图片 306

def intersection(self, *args, **kwargs): # real signature unknown
        """
        Return the intersection of two sets as a new set.

        (i.e. all elements that are in both sets.)
        """
        pass

View Code

举个例子

图片 307图片 308

number = {1,2,3,4,5,6,8,9,13}
number1 = {1,2,3,4,5,13,16,17}
print(number.intersection(number1))
print(number & number1)
#运行结果
{1, 2, 3, 4, 5, 13}
{1, 2, 3, 4, 5, 13}

View Code

.intersection_update()

错落更新,未有重返值,直接更正群集

图片 309图片 310

 def intersection_update(self, *args, **kwargs): # real signature unknown
        """ Update a set with the intersection of itself and another. """
        pass

View Code

举个例证

图片 311图片 312

number = {1,2,3,4,5,6,8,9,13}
number1 = {1,2,3,4,5,13,16,17}
number.intersection_update(number1)
print(number)
#运行结果
{1, 2, 3, 4, 5, 13}

View Code

isdisjoint()

当七个聚众未有交集的时候,重返True,不然重返False

图片 313图片 314

  def isdisjoint(self, *args, **kwargs): # real signature unknown
        """ Return True if two sets have a null intersection. """
        pass

View Code

举例

图片 315图片 316

number = {1,2,3,4,5,6,8,9,13}
number1 = {16,17}
print(number.isdisjoint(number1))
#运行结果
True
number = {1,2,3,4,5,6,8,9,13,16}
number1 = {16,17}
#运行结果
False

View Code

.issubset()

 当有2个群集A和B,A.issubset(B卡塔尔国,A是还是不是被B包蕴,倘若是则赶回True,不然重返False

图片 317图片 318

  def issubset(self, *args, **kwargs): # real signature unknown
        """ Report whether another set contains this set. """
        pass

View Code

举个例证

图片 319图片 320

number = {1,2,3,4,5,6,8,9,13,16,17}
number1 = {16,17}
print(number1.issubset(number))
#运行结果
True

View Code

.issuperset()

当有2个集结A和B,A.issuperset(B卡塔尔(英语:State of Qatar),A是还是不是带有B,假诺含有则赶回True,否则再次回到False

图片 321图片 322

 def issuperset(self, *args, **kwargs): # real signature unknown
        """ Report whether this set contains another set. """
        pass

View Code

举个例子

图片 323图片 324

number = {1,2,3,4,5,6,8,9,13,16,17}
number1 = {16,17}
print(number.issuperset(number1))
#运行结果
True

View Code

.symmetric_difference()

取七个集聚的差集,即取八个聚众中对方都并未有的成分

图片 325图片 326

  def symmetric_difference(self, *args, **kwargs): # real signature unknown
        """
        Return the symmetric difference of two sets as a new set.

        (i.e. all elements that are in exactly one of the sets.)
        """
        pass

View Code

例如

图片 327图片 328

number = {1,2,3,4,5,6,8,9,13,16,17}
number1 = {16,17,18,19}
print(number.symmetric_difference(number1))
#运行结果
{1, 2, 3, 4, 5, 6, 8, 9, 13, 18, 19}

View Code

.symmetric_difference_update()

取四个汇聚的差集,即取八个聚众中对方都没有的成分,并更新到聚集中

图片 329图片 330

   def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
        """ Update a set with the symmetric difference of itself and another. """
        pass

View Code

比如

图片 331图片 332

number = {1,2,3,4,5,6,8,9,13,16,17}
number1 = {16,17,18,19}
number.symmetric_difference_update(number1)
print(number)
#运行结果
{1, 2, 3, 4, 5, 6, 8, 9, 13, 18, 19}

View Code

.update()

取多个聚众的并集,并改过到集合中

图片 333图片 334

  def update(self, *args, **kwargs): # real signature unknown
        """ Update a set with the union of itself and others. """
        pass

View Code

举个例证

图片 335图片 336

number = {1,2,3,4,5,6,8,9,13,16,17}
number1 = {16,17,18,19}
number.update(number1)
print(number)
#运行结果
{1, 2, 3, 4, 5, 6, 8, 9, 13, 16, 17, 18, 19}

View Code

 

View Code

 

View Code

七、字典

在python里面,字典便是生龙活虎层层的 键-值,各样值都与一个值是逐后生可畏对应的,键能够是数字、字符串、列表和字典。实际上,能够将其他python对象用作字典的值。

图片 337图片 338

info = {
    'name':'Frank',
    'age':23,
    'hobbby':'reading',
    'address':'Shanghai',
}
print(info)
print(info['age'])
#运行结果
{'name': 'Frank', 'age': 23, 'hobbby': 'reading', 'address': 'Shanghai'}
23

View Code

办法如下:

.keys()

收取字典的键

图片 339图片 340

   def keys(self): # real signature unknown; restored from __doc__
        """ D.keys() -> a set-like object providing a view on D's keys """
        pass

View Code

举个例证

图片 341图片 342

info = {
    'name':'Frank',
    'age':23,
    'hobbby':'reading',
    'address':'Shanghai',
}
print(info.keys())
#运行结果
dict_keys(['name', 'age', 'hobbby', 'address'])

View Code

.values()

抽出字典的值

图片 343图片 344

  def values(self): # real signature unknown; restored from __doc__
        """ D.values() -> an object providing a view on D's values """
        pass

View Code

比方

图片 345图片 346

info = {
    'name':'Frank',
    'age':23,
    'hobbby':'reading',
    'address':'Shanghai',
}
#运行结果
print(info.values())

View Code

.pop()

 弹出一个键值对,必需钦点键

 举例

图片 347图片 348

info = {
    'name':'Frank',
    'age':23,
    'hobbby':'reading',
    'address':'Shanghai',
}
info.pop('name')
print(info)
#运行结果
{'age': 23, 'hobbby': 'reading', 'address': 'Shanghai'}

View Code

 .clear()

 清空字典里的键值对

图片 349图片 350

 def clear(self): # real signature unknown; restored from __doc__
        """ D.clear() -> None.  Remove all items from D. """
        pass

View Code

 举例

图片 351图片 352

info = {
    'name':'Frank',
    'age':23,
    'hobbby':'reading',
    'address':'Shanghai',
}
info.clear()
print(info)
#运行结果
{}

View Code

 .update()

 更新字典,假设有2个字典A和B,A.update(B卡塔尔(英语:State of Qatar),A和B相仿的键的值会被B更新,而B中平素不的键值对会被增加到A中

图片 353图片 354

  def update(self, E=None, **F): # known special case of dict.update
        """
        D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.
        If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]
        If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
        In either case, this is followed by: for k in F:  D[k] = F[k]
        """
        pass

View Code

 举个例证

图片 355图片 356

info = {
    'name':'Frank',
    'age':23,
    'hobby':'reading',
    'address':'Shanghai',
}
info_new = {
    'age':24,
    'hobby':'sleeping',
    'QQ':'110110',
}
info.update(info_new)
print(info)
#运行结果
{'name': 'Frank', 'age': 24, 'hobby': 'sleeping', 'address': 'Shanghai', 'QQ': '110110'}

View Code

 .copy()

 复制字典

图片 357图片 358

info = {
    'name':'Frank',
    'age':23,
    'hobby':['reading','sleep'],
    'address':'Shanghai',
}
info_new = info.copy()
info['name']='Jack'
info['hobby'][0]='writing'
print(info)
print(info_new)
#运行结果
{'name': 'Jack', 'age': 23, 'hobby': ['writing', 'sleep'], 'address': 'Shanghai'}
{'name': 'Frank', 'age': 23, 'hobby': ['writing', 'sleep'], 'address': 'Shanghai'}

View Code

 我们会发觉和列表中的copy相同,也存在字典里面包车型地铁列表的要素被校订后,复制的字典也会自行校正,那个原因实在和前面包车型大巴是同样的,大家这里也得以运用deep.copy

图片 359图片 360

import copy
info = {
    'name':'Frank',
    'age':23,
    'hobby':['reading','sleep'],
    'address':'Shanghai',
}
info_new = copy.deepcopy(info)
info['name']='Jack'
info['hobby'][0]='writing'
print(info)
print(info_new)
#运行结果
{'name': 'Jack', 'age': 23, 'hobby': ['writing', 'sleep'], 'address': 'Shanghai'}
{'name': 'Frank', 'age': 23, 'hobby': ['reading', 'sleep'], 'address': 'Shanghai'}

View Code

 那字典里的字典会不会现出雷同的主题素材呢?

图片 361图片 362

info = {
    'name':'Frank',
    'age':23,
    'hobby':['reading','sleep'],
    'address':'Shanghai',
    'language':{1:'Python',2:'Go'},
}
info_new = info.copy()
info['name']='Jack'
info['hobby'][0]='writing'
info['language'][2]='Java'
print(info)
print(info_new)
#运行结果
{'name': 'Jack', 'age': 23, 'hobby': ['writing', 'sleep'], 'address': 'Shanghai', 'language': {1: 'Python', 2: 'Java'}}
{'name': 'Frank', 'age': 23, 'hobby': ['writing', 'sleep'], 'address': 'Shanghai', 'language': {1: 'Python', 2: 'Java'}}

View Code

 答案是,是的,当大家想在改换原字典的时候,复制的字典保持不改变,还能够动用deep.copy来缓和这些主题素材。

图片 363图片 364

import copy
info = {
    'name':'Frank',
    'age':23,
    'hobby':['reading','sleep'],
    'address':'Shanghai',
    'language':{1:'Python',2:'Go'},
}
info_new = copy.deepcopy(info)
info['name']='Jack'
info['hobby'][0]='writing'
info['language'][2]='Java'
print(info)
print(info_new)
#运行结果
{'name': 'Jack', 'age': 23, 'hobby': ['writing', 'sleep'], 'address': 'Shanghai', 'language': {1: 'Python', 2: 'Java'}}
{'name': 'Frank', 'age': 23, 'hobby': ['reading', 'sleep'], 'address': 'Shanghai', 'language': {1: 'Python', 2: 'Go'}}

View Code

 这也是大家常说的深浅copy!

.fromkeys()

 用来创立一个新的字典

图片 365图片 366

   def fromkeys(*args, **kwargs): # real signature unknown
        """ Returns a new dict with keys from iterable and values equal to value. """
        pass

View Code

 举个例证

图片 367图片 368

key = (1,2,3,4,5)
value = 'Python'
print(dict.fromkeys(key,value))
#运行结果
{1: 'Python', 2: 'Python', 3: 'Python', 4: 'Python', 5: 'Python'}

View Code

 .get()

 依据键再次回到值,未有键则再次回到None

图片 369图片 370

info = {
    'name':'Frank',
    'age':23,
    'hobby':['reading','sleep'],
    'address':'Shanghai',
}
print(info.get('hobby'))
#运行结果
['reading', 'sleep']

View Code

 .items()

 返回dict_items(卡塔尔国,日常结合for循环使用

图片 371图片 372

info = {
    'name':'Frank',
    'age':23,
    'hobby':['reading','sleep'],
    'address':'Shanghai',
}
print(info.items())
#运行结果
dict_items([('name', 'Frank'), ('age', 23), ('hobby', ['reading', 'sleep']), ('address', 'Shanghai')])

View Code

图片 373图片 374

info = {
    'name':'Frank',
    'age':23,
    'hobby':['reading','sleep'],
    'address':'Shanghai',
}
for k,v in info.items():
    print(k,"---",v)
#运行结果
name --- Frank
age --- 23
hobby --- ['reading', 'sleep']
address --- Shanghai

View Code

.popitem()

 弹出最后叁个键值,会回去三个元组,当弹空字典会报错

图片 375图片 376

 def popitem(self): # real signature unknown; restored from __doc__
        """
        D.popitem() -> (k, v), remove and return some (key, value) pair as a
        2-tuple; but raise KeyError if D is empty.
        """
        pass

View Code

 举个例证

图片 377图片 378

info = {
    'name':'Frank',
    'age':23,
    'hobby':['reading','sleep'],
    'address':'Shanghai',
}
print(info.popitem())
info.popitem()
print(info)
#举个例子
('address', 'Shanghai')
{'name': 'Frank', 'age': 23}

View Code

.setdefault(key,value)

假诺键在字典中,则赶回这么些键的值,假诺不在字典中,则向字典中插入那么些键,并回到value,私下认可value位None
譬喻

图片 379图片 380

info = {
    'name':'Frank',
    'age':23,
    'hobby':['reading','sleep'],
}
print(info.setdefault('name'))   #存在键name,返回值
print(info)
print(info.setdefault('address','shanghai'))  #不存在键address,返回'shanghai',添加键值对
print(info)
print(info.setdefault('QQ'))    #不存在键QQ,添加键QQ,返回None
print(info)
#运行结果
Frank
{'name': 'Frank', 'age': 23, 'hobby': ['reading', 'sleep']}
shanghai
{'name': 'Frank', 'age': 23, 'hobby': ['reading', 'sleep'], 'address': 'shanghai'}
None
{'name': 'Frank', 'age': 23, 'hobby': ['reading', 'sleep'], 'address': 'shanghai', 'QQ': None}

View Code

 

明日就写到这里了,迎接各位大佬提议错误和美中不足,感激了!

 

顾客端类(TestMain)

 

 3.angular.element()  应该用 directive

图片 381图片 382

 

图片 383图片 384

namespace Ptototype_Pattern
{
    class TestMain
    {
        static void Main(string[] args)
        {
            ReSume A = new ReSume("张三");
            A.SetPersonInfo("25","男","1988-10-10");
            A.SetWorkExperice("2010--2013", "X公司");

            ReSume B = (ReSume)A.Clone();
            B.SetWorkExperice("2009--2010", "Y公司");

            ReSume C = (ReSume)A.Clone();
            C.SetWorkExperice("2006--2009", "Z公司");

            A.Display();
            B.Display();
            C.Display();

            Console.ReadLine();

        }
    }
}

 

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>
    <style>
        .a{color:red;}
    </style>
</head>
<body>
    <p>12345</p>
    <script>
        var p1=document.getElementsByTagName("p")[0];
        angular.element(p1).addClass('a');
    </script>
</body>
</html>

View Code

 

View Code

图片 385

 

 4. JSON.stringify(卡塔尔国  // 对象转成string

 

 

图片 386图片 387

深复制和浅复制:MemberwiseClone 方法创立三个外边别本,方法是开创二个新指标,然后将如今指标的非静态字段复制到该新对象。 如若字段是值类型的,则对该字段施行逐位复制。 若是字段是援用类型,则复制援用但不复制援用的目的;因而,原始对象及其复本引用同后生可畏对象。

 

  <script>
        var a={a:1,b:2};
        console.log("xx: " typeof a " :" a);
        var b=JSON.stringify(a);    // 转成string 类型
        console.log("x2x: " typeof b " :" b);
    </script>

援引类型的事比方下:

View Code

新扩展加专门的学业经验类(WorkExperice)

 5.angular.extend(obj2,obj1卡塔尔国  //  把obj1的习性复制给obj2并把结果赋值给obj2  

 

图片 388图片 389

图片 390图片 391

<script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>
    <script>
        var obj1={name:'tom'};
        var obj2={sex:'female'};
        var obj_new=angular.extend(obj2,obj1);    // 返回值赋给obj2
        console.log("obj1: " JSON.stringify(obj1));
        console.log("obj2: " JSON.stringify(obj2));
        console.log("obj_new: " JSON.stringify(obj_new));
    </script>
namespace Ptototype_Pattern
{
    class WorkExperice
    {
        private string workTime;
        private string workCompany;
        /// <summary>
        /// 工作时间
        /// </summary>
        public string WorkTime
        {
            get { return workTime; }
            set { workTime = value; }
        }

        /// <summary>
        /// 工作企业
        /// </summary>
        public string WorkCompany
        {
            get { return workCompany; }
            set { workCompany = value; }
        }
    }
}

View Code

View Code

 6. webStorm 智能提醒jq angularjs语法

 

图片 392

简历类(Resume) :世袭于系统的仿造接口(ICloneable)

 7.评释 controllers 的引入的措施是应用数组表示法

图片 393图片 394

图片 395

namespace Ptototype_Pattern
{
    class ReSume:ICloneable
    {
        private string name;
        private string age;
        private string sex;
        private string birthday;
        //private string time;
        //private string company;
        private WorkExperice work;
        public ReSume(string name)
        {
            this.name = name;
            work = new WorkExperice();

        }

        /// <summary>
        /// 设置个人信息
        /// </summary>
        /// <param name="age"></param>
        /// <param name="sex"></param>
        /// <param name="birthday"></param>
        public void SetPersonInfo(string age, string sex, string birthday)
        {
            this.age = age;
            this.sex = sex;
            this.birthday = birthday;
        }

        /// <summary>
        /// 设置工作经历
        /// </summary>
        /// <param name="time"></param>
        /// <param name="company"></param>
        public void SetWorkExperice(string time, string company)
        {
            //this.time = time;
            //this.company = company;
            work.WorkTime = time;
            work.WorkCompany = company;

        }

        public void Display()
        {
            //Console.WriteLine("姓名:{0}  年龄:{1} 出生日期:{2}", name, age, birthday);
            //Console.WriteLine("在 {0} 工作于 {1} n",time,company);

            Console.WriteLine("姓名:{0}  年龄:{1} 出生日期:{2}", name, age, birthday);
            Console.WriteLine("在 {0} 工作于 {1} n", work.WorkTime, work.WorkCompany);

        }

        public Object Clone()
        {
            return (Object)this.MemberwiseClone();
        }
    }
}

8.angularjs.forEach()  angularjs.fromJson()

View Code

图片 396图片 397

客商端不改变:(全为Z公司)

<script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>
    <script>
        /* 1. angularjs.forEach();  */
        var objs =[{a:1},{a:2}];
        angular.forEach(objs, function(data,index,array){
            //data等价于array[index]
            console.log(data.a '=' array[index].a);
            console.log("xx: " data.a);
        });
        /*  2.  angular.fromJson()  */
        var json='{"name":"haha","password":"321"}';
        var jsonStr=angular.fromJson(json);     //  把json转成对象
        console.log("jsonStr: " typeof jsonStr);
        console.log("jsonStr name: " jsonStr.name);
    </script>

图片 398

View Code

MemberwiseClone 方法成立三个外边别本,对于引用类型复制引用,但不复制援引的目的

 9. ng-class

改为深复制如下:

图片 399图片 400

做事资历类(WorkExperice)

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .testCol{color:blue;}
        .testSize{font-size: 30px;}
        .testBorder{border: 1px solid red;}
        .red{color:red;}
    </style>
</head>

<body>
    <div ng-app="app" ng-controller="myCtrl">

    <p ng-class="{testCol:color,testSize:size,testBorder:border}">{{name}}</p>
                    <!--  属性是样式,值是true or false -->
        <p ng-class="{strike: deleted, bold: important, red: error}">Map Syntax Example</p>
        <input type="checkbox" ng-model="deleted"> deleted (apply "strike" class)<br>
        <input type="checkbox" ng-model="important"> important (apply "bold" class)<br>
        <input type="checkbox" ng-model="error"> error (apply "red" class)
        <hr>


        </div>
        <script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>
        <script>
            angular.module("app",[])
                .controller("myCtrl",["$scope", function ($scope) {
                     $scope.name='haha';
                        $scope.color=true;     /*  true 则应用该样式*/
                        $scope.size=false;
                        $scope.border=true;
                }])
        </script>
</body>
</html>

 

View Code

图片 401图片 402

 10.ng-copy 复制  ng-paste粘贴  ng-cut 剪切

namespace Ptototype_Pattern
{
    class WorkExperice:ICloneable
    {
        private string workTime;
        private string workCompany;
        /// <summary>
        /// 工作时间
        /// </summary>
        public string WorkTime
        {
            get { return workTime; }
            set { workTime = value; }
        }

        /// <summary>
        /// 工作企业
        /// </summary>
        public string WorkCompany
        {
            get { return workCompany; }
            set { workCompany = value; }
        }

        public Object Clone()
        {
            return (object)this.MemberwiseClone();
        }
    }
}

图片 403图片 404

View Code

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>

</head>
<body>
<div ng-app="app" ng-controller="myCtrl">
        <div ng-bind="name"></div>
    <input type="text" ng-model="name" ng-copy="copy()"/>
    </div>
    <script>
        /*触发条件:复制。鼠标右键复制和快捷键Ctrl C都会触发。*/  
        angular.module("app",[])
            .controller("myCtrl",["$scope", function ($scope) {
                 $scope.name='haha';
                    $scope.copy= function () {
                        alert(1);
                    }
            }])

    </script>
</body>
</html>

 

View Code

简历类(Resume) :世襲于系统的仿造接口(ICloneable)

 11.ng-list

图片 405图片 406

图片 407图片 408

namespace Ptototype_Pattern
{
    class ReSume:ICloneable
    {
        private string name;
        private string age;
        private string sex;
        private string birthday;
        //private string time;
        //private string company;
        private WorkExperice work;
        public ReSume(string name)
        {
            this.name = name;
            work = new WorkExperice();

        }
        public ReSume(WorkExperice work)
        {
            this.work = (WorkExperice)work.Clone();
        }

        /// <summary>
        /// 设置个人信息
        /// </summary>
        /// <param name="age"></param>
        /// <param name="sex"></param>
        /// <param name="birthday"></param>
        public void SetPersonInfo(string age, string sex, string birthday)
        {
            this.age = age;
            this.sex = sex;
            this.birthday = birthday;
        }

        /// <summary>
        /// 设置工作经历
        /// </summary>
        /// <param name="time"></param>
        /// <param name="company"></param>
        public void SetWorkExperice(string time, string company)
        {
            //this.time = time;
            //this.company = company;
            work.WorkTime = time;
            work.WorkCompany = company;

        }

        public void Display()
        {
            //Console.WriteLine("姓名:{0}  年龄:{1} 出生日期:{2}", name, age, birthday);
            //Console.WriteLine("在 {0} 工作于 {1} n",time,company);

            Console.WriteLine("姓名:{0}  年龄:{1} 出生日期:{2}", name, age, birthday);
            Console.WriteLine("在 {0} 工作于 {1} n", work.WorkTime, work.WorkCompany);

        }

        public Object Clone()
        {
            //return (Object)this.MemberwiseClone();
            ReSume resum = new ReSume(this.work);
            resum.name = this.name;
            resum.age = this.age;
            resum.birthday = this.birthday;
            return resum;
        }
    }
}
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>
</head>
<body>
<div ng-app="app" ng-controller="myCtrl">
    <p>ng-list自定义输入数组   a.b.c.d </p>
    <input type="text" ng-model="lists" ng-list="."/><br/>
    {{lists}}
    <li ng-repeat="list in lists">{{list}}</li>
    </div>
    <script>
        angular.module("app",[])
            .controller("myCtrl",["$scope", function ($scope) {
                $scope.lists=['a','b','c'];
            }])
    </script>
</body>
</html>

View Code

View Code

客商端不改变:

 12. angular 获得input的值

图片 409

图片 410图片 411

 

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
  <!--<script src="http://apps.bdimg.com/libs/angular.js/1.5.3/angular.min.js"></script>-->
  <script src="//cdn.bootcss.com/angular.js/1.5.3/angular.min.js"></script>
</head>
<body>
<div ng-app="app" ng-controller="myCtrl">
<input type="text" ng-model="orderNum"/>
  <button ng-click="check()">btn</button>
</div>
<script>
  angular.module("app",[])
    .controller("myCtrl", function ($scope) {
      $scope.check= function () {
         alert($scope.orderNum)
      }
    })
</script>
</body>
</html>

 

View Code

 

 13.angular factory service

 

图片 412图片 413

 

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
  <script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>
</head>
<body>
<div ng-app="appTest" ng-controller="MyController">
<ul>
  <li ng-repeat="test in tests">
    id: {{test.id}} 名字: {{test.name}}
    信息: {{test.lastText}}
    <button ng-click="remove(test)">delete</button>
  </li>
</ul>
</div>
<script>
  var appTest = angular.module("appTest",[]);
  appTest.factory("myFactory", function () {
      var f={};
      f.remove= function (arr,item) {
        return arr.splice(arr.indexOf(item),1);
      }
      return f;
    });
  appTest.service("myService", function (myFactory) {
      this.remove=function(arr,item){
        return myFactory.remove(arr,item);
      }
    });
  appTest.controller("MyController", function ($scope,$http,myService) {
      $http.get("test.json").success(function (data) {
        $scope.tests=data;
      });
      //    把factory service 删除,直接在控制器中可以实现删除效果
      /* $scope.remove= function (test) {
       $scope.tests.splice($scope.tests.indexOf(test),1);
       }*/
      $scope.remove= function (test) {
         myService.remove($scope.tests,test);
      }
    });
</script>

</body>
</html>

 

View Code

14.angular 指令(1)

图片 414图片 415

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body ng-app="app">
  <hello-word>12345</hello-word>
  <hello-word></hello-word>
  <script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>
  <script>
    angular.module("app",[])
      .directive('helloWord', function () {
        return{
          restrict:'E',    //  E 元素  A 属性
          template:'<div>hi, how are yousss<br/></div>',
          replace:true,    /* 隐藏 <hello-word>标签 */
          transclude:true     /* 保留 标签里面的内容: 12345 */
        }
      })
  </script>
</body>
</html>

View Code

15.anguar 指令 link

图片 416图片 417

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
  <style>
    .expander {
      border: 1px solid black;
      width: 250px;
    }

    .expander>.title {
      background-color: black;
      color: white;
      padding: .1em .3em;
      cursor: pointer;
    }

    .expander>.body {
      padding: .1em .3em;
    }
  </style>
</head>
<body ng-app="expanderModule">
<div ng-controller='SomeController'>
  <expander class='expander' expander-title='title'>
    {{text}}
  </expander>

</div>
  <script src="http://www.bestsilkbedding.com/uploads/allimg/191212/153P51S5-11.jpg"></script>
  <script>
    var expanderModule=angular.module('expanderModule', [])
    expanderModule.directive('expander', function() {
      return {
        restrict : 'EA',
        replace : true,
        transclude : true,
        scope : {
          title : '=expanderTitle'
        },
        template : '<div>'
          '<div class="title" ng-click="toggle()">{{title}}</div>'
          '<div class="body" ng-show="showMe" ng-transclude></div>'
          '</div>',
        link : function(scope, element, attrs) {
          scope.showMe = false;
          scope.toggle = function toggle() {
            scope.showMe = !scope.showMe;
          }
        }
      }
    });
    expanderModule.controller('SomeController',function($scope) {
      $scope.title = '点击展开';
      $scope.text = '这里是内部的内容。';
    });
  </script>
</body>
</html>

View Code

 

本文由pc28.am发布于计算机编程,转载请注明出处:Python数据类型及其方法详明,设计形式之

上一篇:伪CodeFirst开荒方式接纳于Sqlite数据库 下一篇:没有了
猜你喜欢
热门排行
精彩图文
  • 应用程式开拓平台,Smobiler开采平台
    应用程式开拓平台,Smobiler开采平台
    最前面的话:Smobiler是一个在VS环境中使用.Net语言来开发APP的开发平台,也许比Xamarin更方便 .Net语言 APP开发平台——Smobiler学习日志:如何在手机上实现电
  • NET开拓能源大全
    NET开拓能源大全
    目录 API 应用框架(ApplicationFrameworks) 应用模板(ApplicationTemplates) 人工智能(ArtificialIntelligence) 程序集处理(AssemblyManipulation) 资源(Assets) 认证和授
  • STM32就学笔记之C语言篇
    STM32就学笔记之C语言篇
    【unsigned】 1、rewind(FILE *卡塔尔(英语:State of Qatar):回到文件开头处 2、fprintf(), fscanf(), fgets(), fputs() (1)、fprintf(#FILE *restrict#, #const char *restrict,...#卡塔尔(英语
  • python面向对象三大特征,面向对象
    python面向对象三大特征,面向对象
    面向对象-组合 风流罗曼蒂克、面向进度与面向对象的简要介绍 一、继承 大器晚成 什么是多态动态绑定(在这里起彼伏的背景下行使时,一时也称得上多
  • HttpRuntime的认知与抓好明白,异步HTTP乞请操作
    HttpRuntime的认知与抓好明白,异步HTTP乞请操作
    一、说明 上边最早介绍HttpRuntime的Web.config里的构造 1卡塔尔(英语:State of Qatar) 那些类 是本身 在安分守己项目中,优化驱除实际难题时,不参照第三方代码