Variables and data types for Python
1, Python variables do not need to define the data type in advance, can be changed dynamically
2.Python is all object, variable is an object, has its own properties and methods
We can pass
To see the type of the variable: variable name. __class__
Method of calling Variable: variable name. Method ()
#!/bin/env Python#coding:utf-8#type prints out the type of data print type (1) Print type (1.0) Print type ("HelloWorld") #虚数 such as 12j a = 12j + 1print Aprint type (a) # Division and remainder print "5/3 =%d"% (5/3) print "5 percent 3 =%d"% ( 5% 3) #进制数字打印print "%d,%o,%x"% (10,10,10) #查看变量的类型a = "Hello World " Print a.__class__# method for calling variables print a.split ()
Tuple (tuple)
#!/bin/env python#coding:utf-8# In addition to strings and numeric values, Python provides another 4 important basic types: #元组, lists, collections, and dictionaries. #元组 (tuple): Non-changing data series A = ("First", "second", "third") #输出元组print (a) #打印元组的长度print ("A len:%d"% Len (a)) #遍历元组print ("%s%s% S "% (A[0],a[1],a[2])) #元组中的一个元素被另一个元组引用b = (A," four ") print (b) print ("%s%s%s "% (B[0][0],b[0][1],b[0][2],b[1])) # tuples can be Contains various types of data, but after creation, it is no longer possible to change the # tuple to be immutable. (strings are immutable after they are created, and those that seem to change # their operations actually create new strings) #下面的书写将会报错a [1] = 3
Python Getting Started learning-----variables and underlying types P day