python

初识python

1
2

python安装以及环境配置参考https://www.bilibili.com/video/BV1wD4y1o7AS?p=3&spm_id_from=pageDriver

第一个输出

1
2
3
4
1.文件-新建-新建项目
2.选择项目右键新建-文件名为first.py
3.书写print("hello world");
4.点击空白位置右键run first


输出(print)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#输出数字
print(520);
print(98.5);

#输出字符串
print("123s");
print('123as');

#输出含有运算符的表达式
print(3+1); #输出4

#输出到文件中
fp=open('D:/test.txt','a+'); #输出到d盘下面
print('helloworld',file=fp); #输出内容为 helloworld
fp.close();

#不进行换行输出(输出内容在一行) --用逗号隔开
print('hello','world','Python');

输出其他内容

输出到文件里面


转义字符和原字符(r/R+字符串)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

print('--1.转行(分行)-------------');
print('hello\nworld');

print('--2.制表(四个字符为一个)-------------');
print('hello\tworld');
print('helloooo\tworld'); #四个字符是一个\t

print('--3.回车功能(覆盖符号之前的所有内容)---');
print('hello\rworld'); #hello输入之后回车world会把hello挤掉

print('--4.退一个格功能--------------');
print('hello\bworld');

print('--5.将字符串里面的单引号不被识别为转义字符---------------------------');
print('老师说:\'给我考满分\'');

print('--不希望转义字符起作用,使用原字符(字符串前面加r/R)------');
print(r'hello\nworld');
print(r'hello\nworld\\'); #注意:最后两个是\\ √
print(r'hello\nworld\'); #注意:最后一个字符不能是\ ×


标识符和保留字

1
类似于java和c语言

后续

1
2

俺买了python从入门到实践,看书去了!

×

纯属好玩

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

文章目录
  1. 1. 初识python
    1. 1.1. 第一个输出
  2. 2. 输出(print)
  3. 3. 转义字符和原字符(r/R+字符串)
  4. 4. 标识符和保留字
  5. 5. 后续
,