* { margin: 0; padding: 0; } .about { width: 100%; height: 100%; overflow: hidden; } .about_bgc { width: 100% } .about_tit { position: absolute; top: 280px; left: 0; right: 0; font-size: 28px; font-weight: 550; bottom: 0; width: 800px; margin: auto; text-align: center; } .ribbon { display: flex; justify-content: center; position: absolute; right: 300px; top: 50px; margin: auto; } .ribbon:after, .ribbon:before { margin-top: 0.5em; content: ""; display: flex; ; border: 1.5em solid #fff; } .ribbon:after { border-right-color: transparent; } .ribbon:before { border-left-color: transparent; } .ribbon a:link, .ribbon a:visited { color: #000; text-decoration: none; height: 3.5em; overflow: hidden; } .ribbon span { background: #fff; display: inline-block; line-height: 3em; padding: 0 1.5em; margin-top: 0.5em; position: relative; -webkit-transition: background-color 0.2s, margin-top 0.2s; /* Saf3.2+, Chrome */ -moz-transition: background-color 0.2s, margin-top 0.2s; /* FF4+ */ -ms-transition: background-color 0.2s, margin-top 0.2s; /* IE10 */ -o-transition: background-color 0.2s, margin-top 0.2s; /* Opera 10.5+ */ transition: background-color 0.2s, margin-top 0.2s; } .ribbon a:hover span { background: #FFD204; margin-top: 0; } .ribbon span:before { content: ""; position: absolute; top: 3em; left: 0; border-right: 0.5em solid #9B8651; border-bottom: 0.5em solid #fff; } .ribbon span:after { content: ""; position: absolute; top: 3em; right: 0; border-left: 0.5em solid #9B8651; border-bottom: 0.5em solid #fff; } .me { display: flex; justify-content: center; margin-top: 60px; overflow: hidden; } .me_tit { width: 600px; line-height: 36px; font-size: 18px; margin-left: 100px; margin-top: 50px; } .me_img { width: 800px; height: 600px; } .animate { padding-left: 20px; width: 500px; font-size: 16px; color: #000; animation: 10s wordsLoop linear infinite normal; } @keyframes wordsLoop { 0% { transform: translateY(100px); -webkit-transform: translateY(100px); } 100% { transform: translateY(-100%); -webkit-transform: translateY(-100%); } } .videos { display: flex; margin-top: 60px; padding-bottom: 80px; } .videos span { width: 400px; margin-right: 100px; margin-left: 300px; color: #FFD204 }

Python 笔记 1(前期准备)

Python 基础

1.基本操作

  • crtl + s 保存
  • “#”表示注释(单行)
  • ‘‘‘ ’’’多行注释
  • “\”表示行的链接(如a=zxcvbnm ||a=zxcv
    bnm )

2.对象

包括标识,类型,值
例:
Python中一切皆对象
对象的本质就是:内存块

a
id 1903362074992
type int
---- ---- ----
value 3

3.引用

变量:引用对象
变量位于:栈内存
对象位于:堆内存

  • Python为动态语言(例:a=3不需要写成int a=3)

4.标识符

标识符:用于变量、函数、类、模块等名称
1.区分大小写(Ljc 与 ljC含义不同)
2.以数字、字母、下划线组成(不能以数字开头)
3.不能使用关键字
4.避免以双下划线开头和结尾,有特殊含义(init

  • 查看关键字>>>help()
    help>keywords

    help>quit
    返回交互模式

5.基本运算

运算符 说明 实例 结果
+ 加法 1+2 3
- 减法 2-1 1
* 乘法 1*2 2
/ 浮点数乘法 4/2 2.0
// 整数除法 9//4 2
% 求余(模) 7%4 3
** 2**3 8

6.使用int类型的转换

1.浮点型直接舍去小数部分
例:
不是四舍五入*
2.对于布尔值 True 转化为1
False 转化为0 (注意开头字母大写)
例:


3.字符串
若只含数字:“12345”直接转为12345
若含有字母:报错
例:
4.自动转换类型
整数+浮点数自动转换为浮点数
例:

7.运算符

  • 关系运算符
  • 逻辑运算符

    注意:与C语言中含义有差别
  • 同一运算符
    同一运算实际上比较的是对象的存储地址

    is与==的区别*
    is是判断对象是否同一,比较其地址
    ==判断对象是否相等,比较其数值
    例:

字符串

1. Python 3 支持16位Unicode编码,可以表示世界上任何形式的字符串

可以使用内置函数 ord()将字符串转换为Unicode吗
可以使用内置函数 chr()将十进制数字转换为字符串
例:

2.创建字符串

使用单引号或双引号均可;但如果字符串内部有符号就不能与之重复
例:
诺需要引用多行字符串,则需使用三个单引号(或双引号)
例:

  • Python中允许空字符串存在
    例:
  • len()函数 用于计算字符串含有多少字符
    例 ;

3.转义字符

/+特殊字符 实现难以铜字符实现的效果

4.字符串的复制

使用“*”
例:

5.不换行打印

使用end=‘’

6.不适用end换行

例:

7.使用end=‘’

例:

8.str()函数 将数字转换为字符串

9.使用[]提取字符

提取规则:

字符串 a b c d e f g
正向搜索 序号 0 1 2 3 4 5 6
反向搜索 序号 -7 -6 -5 -4 -3 -2 -1

例:

10.字符串内容的替换 .replace(,)

1.替换后原来的字符串不变,只是生成一个新的字符串
例:
2.如何替代原来的字符串
例:

11.字符串切片 slice操作

注释: 一般取头不取尾
标准格式:[起始偏移量 start:终止偏移量 end:步长 step]

若取值为负数

实例:
A:将字符串倒序排列

B:提取字符串中所有“s”

12.字符串的分割split()和join()合并

一:空白分割(默认换行符/空格/制表符分割)
例:

二:连接



不做要求时均可使用
测试拼接符+ 与join()的效率代码

import time

time01 = time.time() #起始时间
a=""
for i in range(1000000):
a+="tdxy"
time02 = time.time() #终止时间
print("拼接符“+”运算时间:"+str(time02-time01))

time03=time.time() #起始时间
li = [ ]
for i in range(1000000):
li.append("tdxy")
a="".join(li)
time04=time.time() #终止时间
print("join()运算时间:"+str(time04-time03))


13.字符串比较

==比较数值
is;is not比较地址
in;not in判断包含关系
例:

常用查找方法


去除收尾字符

大小写的转换

格式排版

字符串格式化 format

填充与对齐

^ < >分别表示居中,左,右对齐
:后带填充的字符,只能是一个字符,不填默认空格


数字格式化

可变字符串

io.stringIO
使用前先导入io

posted @   #鲁班一号#  阅读(62)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示