1、整数: int
2、浮点数(小数):float
3、转义字符:/ ,(\n:换行,\t:制表符,\\:\)
4、多个换行:'''...'''
print('''hello
tomorrow
11''')
hello
tomorrow
11
5、布尔值:True,Flase
>>> 3>2
True
>>> 3>4
False
布尔值可以用and ,or ,not计算
age=20
if age >= 18:
print('shaonian')
else:
print('dashu')
shaonian
-----------------------------
age=int(input('please enter your agers:'))
if age >= 18:
print('shaonian')
else:
print('dashu')
please enter your agers:20
shaonian
6、空值,(空值是Python里一个特殊的值,用None
表示。None
不能理解为0)
7、变量
动态语言
>>> a=123
>>> print(a)
123
>>> a='中间'
>>> print (a)
中间
---------------------------
静态语言
x=10
x=x+2
>>> print(x)
12
在程序中,赋值语句先计算下方的表达式x + 2,得到结果12,再赋给变量x。由于x之前的值是10,重新赋值后,x的值变成12。
a='abc'
b=a
a='xyz'
print(b)
abc
8、常量(在Python中,通常用全部大写的变量名表示常量)
>>> 10//3
3
>>> 10/3
3.3333333333333335
>>> 10%3
1
--------------------------------
n=123
f=456.789
s1='Hello,world'
s2='Hello,\'adam\''
s3=r'hello,"bart"'
s4=r'''hello,
lisa!'''
print('n=',n,'\nf=',f,'\ns1=',s1,'\ns2=',s2,'\ns3=',s3,'\ns4=',s4)
n= 123
f= 456.789
s1= Hello,world
s2= Hello,'adam'
s3= hello,"bart"
s4= hello,
lisa!
------------------------------
name=input('please entry your name')
age=input('please entry your age')
city=input('please input your city')
print('name=,',name,'\nage=',age,'\ncity=',city)
please entry your namemike
please entry your age33
please input your cityjiujiang
name=, mike
age= 33
city= jiujiang