基础语法
(1)输出语句:print()
例:print(“hello world,My name is lucy”) 页面打印:hello world,My name is lucy
(2) 输入语句:input()
(3)引用变量
1、字符变量引用
name=“战三” pr int(“你好,我的名字是%r”%name) 页面打印:你好,我的名字是战三
name=“Tom” print(“hello,%s”%name) 页面打印:hello Tom
2、数字变量引用
width=200 print(“width is %d”%dwidth)
注:%r表示可以输入任何的数据类型;%d只能输入数字类型
常用数据类型
(1)整数
例:x=5 y=6
z=x+y
print(z)或是print(x+y)
(2)浮点数
例:f=5.3 m=2.1
d=f+m
print(d)或print(f+m)
(3)字符串
例:str=“今天是一个艳阳天,蓝天白云微风拂面”
print(str)
(4)转义字符
1、“\n”代表换行
例:print(“hello \n world”)
输出的结果为:hello
world
2、“\”转义作用是单斜杠
print(“C:\python35") 实际的意思是:c:\python35 C盘下面的python35文件夹
print(“c:\python35”) 实际意思就是:c:\python35打印而已
3、‘jack’\表示转义单引号
例:print(“my good friends is ‘dog’\”) 打印为:my good friends is ‘dog’
4、“jack”\
例:print(“my good friends is “sunnny”\”) 打印为:my good friends is “sunny”
5、布尔值(true or false)
例:a=3
b=4
print(a=b) 结果输出:false
例:a=3 b=3
print(a=b) 结果输出:true