python学习笔记(二):基础知识点
python基本元素
7 // 2
3
7 % 3
1
# 取商以及余数
divmod(7,3)
(2, 1)
1j*1j
(-1+0j)
10/3
3.3333333333333335
'3,''1.00e2'
'3,1.00e2'
'3,' + '1.00e2'
'3,1.00e2'
'na'*3
'nanana'
'na'[0:1]
'n'
w = ''
if w:
print("hh")
else:
print("hhh")
hhh
count = 1
while count <=5:
print(count)
count += 1
1
2
3
4
5
while True:
stuff = input('string to capitalize[type q to quit]: ')
if stuff == "q":
break
print(stuff.capitalize())
string to capitalize[type q to quit]: q
不能将可变的数据类型当作函数的参数值
字符串处理
import unicodedata
name = unicodedata.name('\u2603')
value = unicodedata.lookup(name)
value
'☃'
place = 'caf\u00e9'
place
'café'
place = '\N{LATIN SMALL LETTER E WITH ACUTE}'
a = place.encode('utf-8') # 编码
a
b'\xc3\xa9'
b = a.decode('utf-8') # 解码
b
'é'
'%d%%' % 32
'32%'
import re
source = "¥马冬梅.com"
m = re.search(r'\w*', source)
m.group()
''
import string
pri = string.printable
re.findall('/.', pri)
['/:']
import re
source = "<b>frf<b>"
m = re.findall(r'<.+>', source)
m
['<b>frf<b>']
pome = '''thewrj ok poj 'po
jio lkn
;jij
j; %%javascriptjoij
j;oi joijl
jiojioj;oij
'''
len(pome)
79
fout = open('datas', 'wt')
fout.write(pome)
79
fout.close()
fin = open('datas', 'r')
pomes = fin.read()
fin.close()
pomes
"thewrj ok poj 'po \njio lkn \n;jij \nj; %%javascriptjoij \nj;oi joijl \njiojioj;oij\n"
fout = open('oops.txt', 'wt')
print('hollow word!', file = fout)
fout.close()
import os
os.path.exists('./oops.txt')
True
name = "oops.txt"
os.path.abspath('oops.txt')
'D:\\Code\\Python\\code\\oops.txt'
os.remove(name)
---------------------------------------------------------------------------
PermissionError Traceback (most recent call last)
<ipython-input-27-a353836641f9> in <module>()
----> 1 os.remove(name)
PermissionError: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'oops.txt'
os.listdir('.')
['.ipynb_checkpoints',
'introducting python.py',
'Introduction.ipynb',
'oops.txt']
os.getcwd()
'D:\\Code\\Python\\code'
import calendar
calendar.isleap(2000)
True
from datetime import date
hallo = date(2014, 10, 31)
hallo.day
31
hallo.isoformat()
'2014-10-31'
now = date.today()
now
datetime.date(2018, 2, 7)
from datetime import timedelta
one = timedelta(days = 1)
tom = now + one * 6
tom
datetime.date(2018, 2, 6)
from datetime import time
noon = time(12, 0, 0)
noon.hour
12
from datetime import datetime
now = datetime.now()
now
datetime.datetime(2018, 1, 31, 15, 30, 45, 978714)
import time
now = time.time()
now
1518007860.2188663
time.ctime(now)
'Wed Jan 31 15:34:00 2018'
time.localtime(now)
time.struct_time(tm_year=2018, tm_mon=1, tm_mday=31, tm_hour=15, tm_min=34, tm_sec=0, tm_wday=2, tm_yday=31, tm_isdst=0)
time.gmtime(now)
time.struct_time(tm_year=2018, tm_mon=1, tm_mday=31, tm_hour=7, tm_min=34, tm_sec=0, tm_wday=2, tm_yday=31, tm_isdst=0)
fmt = "It's %A, %B %d, %Y, local time %I:%M:%S:%p"
t = time.localtime()
t
time.struct_time(tm_year=2018, tm_mon=2, tm_mday=7, tm_hour=20, tm_min=51, tm_sec=5, tm_wday=2, tm_yday=38, tm_isdst=0)
time.strftime(fmt, t)
"It's Wednesday, January 31, 2018, local time 03:46:19:PM"
fmt = "%Y-%m-%d"
time.strptime("2014-04-28", fmt)
time.struct_time(tm_year=2014, tm_mon=4, tm_mday=28, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=118, tm_isdst=-1)
python学习笔记(二):基础知识点的更多相关文章
- Python学习笔记之基础篇(-)python介绍与安装
Python学习笔记之基础篇(-)初识python Python的理念:崇尚优美.清晰.简单,是一个优秀并广泛使用的语言. python的历史: 1989年,为了打发圣诞节假期,作者Guido开始写P ...
- python学习笔记(二)、字符串操作
该一系列python学习笔记都是根据<Python基础教程(第3版)>内容所记录整理的 1.字符串基本操作 所有标准序列操作(索引.切片.乘法.成员资格检查.长度.最小值和最大值)都适用于 ...
- Python 学习笔记二
笔记二 :print 以及基本文件操作 笔记一已取消置顶链接地址 http://www.cnblogs.com/dzzy/p/5140899.html 暑假只是快速过了一遍python ,现在起开始仔 ...
- (10.1)Python学习笔记二
1.在项目工程中要模块化测试一个开发的功能,在测试通过后交付给项目组其他人员继续开发.要保证代码开发的性能和效率以及可扩展性. 2.项目工程中的文件夹分类要功能模块明确清晰,在python中引入某一个 ...
- https学习笔记二----基础密码学知识和python pycrypto库的介绍使用
在更详细的学习HTTPS之前,我也觉得很有必要学习下HTTPS经常用到的加密编码技术的背景知识.密码学是对报文进行编解码的机制和技巧.可以用来加密数据,比如数据加密常用的AES/ECB/PKCS5Pa ...
- Python学习笔记之基础篇(二)python入门
一.pycharm 的下载与安装: 使用教程:https://www.cnblogs.com/jin-xin/articles/9811379.html 破解的方法:http://xianchang. ...
- python学习笔记之基础二(第二天)
1.编码转换介绍 unicode是最底层.最纯的,会根据终端的编码进行转化展示 一般硬盘存储或传输为utf-8(因为省空间.省带宽),读入内存中为unicode,二者如何转换 a = ' ...
- python学习笔记二 数据类型(基础篇)
Python基础 对于Python,一切事物都是对象,对象基于类创建 不同类型的类可以创造出字符串,数字,列表这样的对象,比如"koka".24.['北京', '上 ...
- python学习笔记(基础二:注释、用户输入、格式化输出)
注释 单行:# 多行:上下各用3个连续单引号或双引号 3个引号除了多行注释,还可以打印多行 举例: msg = ''' name = "Alex Li" name2 = name ...
- python学习笔记(基础四:模块初识、pyc和PyCodeObject是什么)
一.模块初识(一) 模块,也叫库.库有标准库第三方库. 注意事项:文件名不能和导入的模块名相同 1. sys模块 import sys print(sys.path) #打印环境变量 print(sy ...
随机推荐
- Chapter 5 Order Inversion Pattern
5.1 Introdution The main focus of this chapter is to discuss the order inversion (OI) pattern, which ...
- angularJs购物金额实例操作
<!DOCTYPE HTML> <html ng-app> <head> <meta http-equiv="Content-Type" ...
- GPU性能:光栅化、图层混合、离屏渲染
So, shouldRasterize will not affect the green/red you see using Instruments. In order to have everyt ...
- POJ3907 Build Your Home
嘟嘟嘟 题意:按逆时针或顺时针给出一个多边形,求面积. 解法:直接套用公式:\(S = \frac{1}{2}|\sum _ {i = 1} ^ {n} {v_i \times v_{i + 1}}| ...
- HDU 4652 Dice
嘟嘟嘟 题目大意就是对于一个m面的骰子,回答这么两个问题: 1.求连续扔n次都是同一数字的期望次数. 2.求连续扔n次每一次数字都不相同的期望次数. 对于期望dp特别菜的我来说,这道题已经算是很难了. ...
- xss练习平台及writeup
今天玩了一天的xss. 分享几个xss game https://xss.haozi.me/#/0x00 http://47.94.13.75/test/ writeup:http://www.cn ...
- face++
1.链表反转 2.快排 3.m*k n*k两矩阵计算欧几里得距离np.tile 4.链表排序,要求时间复杂度小于O(N^2),空间O(1),不允许改变链表的值 5.2sum及其变体 6.给一个数组 ...
- Linux Ubuntu出去看看
转到Ubuntu开发之后,发现不能像之前在Windows下一样直接使用GUI客户端出去看看.于是开始找梯子. 由于我的服务器端已经配置好了,只需要配置本地端即可.整个配置过程分为两步:第一步是安装本地 ...
- PAT——1029. 旧键盘
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及实际被输入的文字,请你列出肯定坏掉的那些键. 输入格式: 输入在2行中分别给出应该输入的文字.以及实际 ...
- Linux下jmap命令查看内存使用
Linux下jmap命令查看内存使用 jmap -heap 1234(1234为进程号) jmap是JDK自带的一个工具,非常小巧方便,其支持参数如下: -heap 打印heap空间的概要 ...