Python基础语法

基础语法
(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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值