Python変数タイプ(l整型,長整形,浮動小数点型,複数,リスト,メタグループ,辞書)学習

9482 ワード

#coding=utf-8
__author__ = 'Administrator'

#Python    

#Python  ,python            int   long    float    complex  
var1 = 10; #    
var2 = 678L #     
var3 = 12.34;#     
var4 = 123j #  
var5 = 123+45j #  

print(var1)
print(var2)
print(var3)
print(var4)
print(var5)
print(var4+var5)

#Python   
str1 = "I love Python"
"""
python      2     :
        0   ,           1
        -1   ,          
"""
print(str1)
#           
print(str1[0])
#     2-5     ,   5
print(str1[2:5])
#                
print(str1[2:])
#       
print(str1*2)
#     
print(str1 +"sunpengwei")
str2 = "qwerty"
print(str2[-4:])#                  
print(str2[-3:-1])#                    

#Python  ,List Python            
#                   。     ,  ,           (    )。
l1 = [1,2,3,4,5,6]
l2 = [7,8,9,1,2,4]
print(l1)#      
print(l1[1])#         
print(l1[2:3])#           
print(l1*2)#      
print(l1+l2)#       

#Pythona  ,   "()"  。         。          ,       。
tuple1 = (1,2,3,4)
print(tuple1)#
print(tuple1[1])
#tuple1[1] = 10        ,   ,         
print(tuple1)

#Python  
"""
  (dictionary)      python              。          ,          。
         :               ,         。
   "{ }"  。     (key)      value  。

"""
dictionary1 = {"key1":"value1",12:34,'key2':'value2'}
print(dictionary1)#       
print(dictionary1["key1"])#  key  value
print(dictionary1.keys())#     key
print(dictionary1.values())#     value

#Python      
"""   ,                ,       ,                。
                      。            ,      。"""
m = "12"
print type(m)
# m   int  
m = int(m)
print(type(m))

s = "qweqwr"
print(tuple(s))#   s       
print(list(s))#   s       

"""

int(x [,base])

 x       


long(x [,base] )

 x        


float(x)

 x        


complex(real [,imag])

      


str(x)

    x       


repr(x)

    x          


eval(str)

            Python   ,       


tuple(s)

    s        


list(s)

    s        


set(s)

       


dict(d)

      。d         (key,value)  。


frozenset(s)

        


chr(x)

            


unichr(x)

        Unicode  


ord(x)

             


hex(x)

                 


oct(x)

                


"""