数值:
int、long(Python2.2以后,long整型认为是int)、float
a=1 b=2**128 c=2.00 print(type(a)) print(type(b)) print(type(c)) <class 'int'> 1 <class 'int'> 340282366920938463463374607431768211456 <class 'float'> 2.0
字符串:Python中,加了引号的字符都是字符串
#Python中,加了引号的都是字符串,数字加引号也看做字符串 name1 = "suyp1" #双引号 name2 = 'suyp2' #单引号 name3 = '''suyp3''' #三个单引号 age = 18 age2 = "18" #数值加引号也认为是字符串 print(type(name1),name1) print(type(name2),name2) print(type(name3),name3) print(type(age),age) print(type(age2),age2) <class 'str'> suyp1 <class 'str'> suyp2 <class 'str'> suyp3 <class 'int'> 18 <class 'str'> 18
字符串的三种引号的用法:
#如果一行字符串中没有单引号出现,此时使用双引号或单引号都可以,如果句子中有单引号出现就必须使用双引号 #变量的值如果有多行,就必须使用多引号 msg1 = "My name is suyp,I'm 18 years old" msg2 = ‘My name is suyp,I'm 18 years old’ #此行会报错 msg3 = ''' 人生苦短, 我用Python! 运维都应该去学开发!! ''' print(msg1) print(msg2) print(msg3)
字符串的运算:
字符串也可以做运算,但只能做‘相加’或者‘相乘’
字符串只能和字符串进行拼接,不能跨类型拼接
n1 = "Su" n2 = "yp" print(n1+n2) print(n1*5)
布尔值:
True/False
C:Userssuyp>python Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a=1 >>> b=2 >>> a>b False >>> a<b True >>>
a = 1 b = 2 if a > b: print("a is bigger than b") else: print("a is smaller than b")