03元祖

4305 ワード

1.         ,      ,       ,
          (       、  ),
             (),  
>>>temp = (1, 2, 3, 4)
>>>temp
>>>(1, 2, 3, 4)
>>>type(temp)
>>><class 'tuple'>#  
>>>
>>>temp(1)  #        
>>>temp
>>>1
>>>type(temp)
>>><class 'int'>#temp int  ,       ()           
>>>temp(1,)
>>>type(temp)
>>><class 'tuple'>  #      ‘,‘ ,     ,     ’()'
>>>temp[::]
>>>(1,)
>>>#      ,    
>>> 2 * (2)
4
>>> 2 * (2,)
(2, 2)
>>> 
2.       
>>> temp = (1, 2, 3, 4)
>>> temp[1] = 3 #       
Traceback (most recent call last):
  File "", line 1, in <module>
    temp[1] = 3
TypeError: 'tuple' object does not support item assignment
>>> temp = (1, 2, 3, 4)#   2    1234
>>>temp 1 = (1234,)
>>> temp = temp[:2] + temp1 + temp[2:]
>>> temp
(1, 2, 1234, 3, 4)
>>> 
3.      
      
>>> del temp #             ,       
>>> temp
Traceback (most recent call last):
  File "", line 1, in <module>
    temp
NameError: name 'temp' is not defined
>>> 
      、