智普教育Python视频教程之入门基础篇,python笔记

2022-10-26,,,,

智普教育Python视频教程之入门基础篇,python笔记

print

id()内存地址

type()变量类型

windows命令行下edit命令

python数据类型不需要指定类型

定义hostname="www.google.com"

结果运行后总是告诉我NameError: name 'socket' is not defined

哪位帮我分析一下,怎么改才对

没用过socket,不过你试着在第一行加入

import socket

C:\>notepad somefile.txt

You could also create a .bat file, edit.bat, to replace the 16-bit edit program

(removed because x64 windows flavors won't run it) which would launch your

favorite editor.

@echo off

notepad %1

@echo on

This is what I wound up doing as a simple patch so I could carry on the way I

always had for the most part. Just type:

edit myfile.ext

in the command prompt to use it.

Note: notepad is not my favorite editor - this is just an example that will

work with stock windows.

Note 2: @echo off and @echo on are shown for clarity. You may also shorten this

by omitting the echo statements and simply placing the @ before the command to

be silenced.

@notepad %1

函数库分类及标准库示例:

字符函数库

网络import socket

gethostbyname

数学函数import math

操作系统库函数import os

listdir

getcwd

使用第三方库函数库httplib2

import urllib

import webbrowser

url='http://www.163.com'

content=urllib.request.urlopen(url).read()

print(content)

open('163.com.html','wb').write(content)//把读到内容写入到文件

webbrowser.open_new_tab('163.com.html')

webbrowser.open_new_tab('http://www.jeapedu.com')

module_name.method(parameters)

alias_module_name.method(parameters)

用Python3.4运行后,提示如下

"AttributeError: 'module' object has no attribute 'urlopen'"

原因是Python3里的urllib模块已经发生改变,此处的urllib都应该改成urllib.request。

TypeError: must be str, not bytes错误:

解答: 写文件处 open(filename, 'w').write 应该写为 open(filename, 'wb').write

最常见的情况是tab和空格的混用会导致错误,或者缩进不对,而这是用肉眼无法分别的。

在编译时会出现这样的错IndentationError:expected an indented block说明此处需要缩

进,你只要在出现错误的那一行,按空格或Tab(但不能混用)键缩进就行。

往往有的人会疑问:我根本就没缩进怎么还是错,不对,该缩进的地方就要缩进,不缩进

反而会出错,,比如:

if xxxxxx:

(空格)xxxxx

或者

def xxxxxx:

(空格)xxxxx

还有

for xxxxxx:

(空格)xxxxx

一句话 有冒号的下一行往往要缩进,该缩进就缩进

if表达式构造:非0即真

自定义函数基础:

有形参和无形参解析,

print缩进不同:

注释用#

单返回值和多返回值

接收多返回值:

自定义函数参数预定义值问题解析:

冲掉预设值:

自定义函数实参赋值顺序:

Python文件操作基础

数据存放在RAM中,

向文件写多行:

方括号/大括号括起来:

Python文件格式化写入:

7.环体while基础

While网络刷博器爬虫:

Taskkill命令杀掉应用程序,杀死网页:

改进:

8.For循环, 分list,tuple,strings,files四种:

(1)strings

(2)list

奇数:

For遍历文件和元组

用小括号括起来是元组,用中括号括起来是list:

把forttest.py文件读取并写入到temp.txt中:

9. python字符串操作:

转义字符:

连接两个字符串:

数字和字符串连接:

相同字符连接:

字符串切片:

索引-1表示从后往前数第一个:

字符串逆序:

前三个用逗号分开, 输出在一行:

Help(str)查看字符串有哪些函数。

Ord将字符转换为ASCII码,chr将ASCII转换为字符:

Find

find从左边查找到第一个字符返回其索引:

rfind从右查找到第一个字符返回其索引:

Strip去掉左边空格:

split以空格标志拆分字符串:

Split以点拆分字符串:

拆分后按索引输出:

0904 Python字符串常用函数2视频教程

0905 Python字符串综合应用实例:字符串分割程序设计与实现

1101 Python列表基本概念及访问使用视频教程

1102 Python列表的基本操作使用与常用函数(1)

1103 Python列表的基本操作使用与常用函数(2)

1105 Python列表与文件读写基础视频教程

1106 Python混合型数据项列表与文件读写

090601 Python字符串综合应用实例:split程序设计与实现(上)

090602 Python字符串综合应用实例:split程序设计与实现(下)

100502 for循环体与文件(迭代器解析)

智普教育Python视频教程之入门基础篇,python笔记的相关教程结束。

《智普教育Python视频教程之入门基础篇,python笔记.doc》

下载本文的Word格式文档,以方便收藏与打印。