学习所看的视频来源于B站,授课老师:Mosh Hamedani老师

视频网址:python教程2019版 6小时完全入门 并且达到能开发网站的能力 目前最好的python教程 (含中文翻译)_哔哩哔哩_bilibili

目录

一、执行Python代码

第一个程序

第二个程序

二、知识点

(一)转换变量类型

(二)引号

1、单引号、双引号

2、三引号

(三)取值

(四)定义参数

(五)大小写

(六)find()、replace()

(七)字符串中是否包含‘Python’?

(八)基础运算

(九)数学函数

(十)语句

(十一)逻辑运算符  (and  or  not)

比较运算符(>  <  >=  <=  ==  !=)

实践一  体重单位 磅 和 千克 的转化器

(十二)while 循环

实践二 猜谜游戏

实践三 汽车开车

(十三)for 循环

练习  (计算购物车中所有商品的总成本)

(十四)嵌套循环

练习1 打印出多维数组

练习2(编写程序打印出下列图像)

(十五)列表

练习(编写程序找出列表中最大的数)

(十六)插入  .append()     .insert()

(十七)删除  del    .remove()   .clear()    .pop()

(十八)排序  .sort()    .reverse()

(十九)查询索引index()   列表中某元素的个数count()

(二十)浅拷贝.copy()

练习(写一个程序,删除我们列表上的副本(重复项))

(二十一)矩阵

(二十二)元组

(二十三) 字典

练习1(将输入的号码(数字)翻译成英文打印出来)

练习2(表情包转换器1)

(二十四)函数function

函数中定义参数

返回函数 return()

练习(表情转换器(2))

(二十五)怎么处理错误?

​ 进行错误处理后 (try expect)

0在除法中的错误(zero division error)

(二十六) 类

构造函数

练习(定义一个名为person的新类型,这些person对象应该有一个name属性和一个对话方法)

(二十七)Python的继承

(二十八)Python的模块

练习(创建一个find_max函数:获取一个列表,并返回最大值max放在模块utils中,并调用使用)

(二十九) Python 的包

导入包中模块

(三十) python里的标准库

random.py 生成随机值

练习(得到两个随机值的元组) (类:dice    函数:roll)

(三十一)使用目录

三、实践

(一)如何安装来自pypi.org的软件包:

(二)如何使用Excel文件


一、执行Python代码

  1. 打开pycharm编辑器
  2. 新建一个Python file
  3. 命名文件
  4. 编程
  5. 运行:编辑完后Ctrl+'s'保存,然后右击鼠标run这个文件

变量:整数、浮点、字符串、布尔值

第一个程序

name=input('what is your name? ')
print('Hi '+name)

 第二个程序

字符串不能和整数、浮点数直接运算

birth_year=input('birth year: ')
age = 2019 - birth_year
print(age)

二、知识点

(一)转换变量类型

整数      int()

浮点型  float()

布尔值  bool()

1.

birth_year=input('birth year: ')
age = 2019 - int(birth_year)
print(age)
birth year: 2001
18

2.

weight_kg=input('weight(kg): ')
weight_lbs=int(weight_kg)/0.45
print(weight_lbs)
weight(kg): 46
102.22222222222221

(二)引号

1、单引号、双引号

course1="python's course for beginners"
course2='python for "beginners"'
print(course1)
print(course2)
python's course for beginners
python for "beginners"

2、三引号

打印多行

course='''
Hi John,here is our first email to you.thank you,
the support team
'''
print(course)
Hi John,here is our first email to you.thank you,
the support team

(三)取值

course='python for beginners'
print(course[0])#正取值
print(course[-1])#逆取值
print(course[0:3])
print(course[0:8:2])#隔空取值
print(course[8:0:-1])#逆向隔空取值
print(course[:])#拷贝
print(course[0:])
print(course[0:len(course)])
p
s
pyt
pto
of nohty
python for beginners
python for beginners
python for beginners

(四)定义参数

first="john"
last="smith"
massage=first+' ['+last+'] is a corder'
msg=f'{first} [{last}] is a corder'
print(massage)
print(msg)
john [smith] is a corder
john [smith] is a corder

(五)大小写

course="Python for Beginners"
print(course.upper())
print(course.lower())
print(course.title())
PYTHON FOR BEGINNERS
python for beginners
Python For Beginners

(六)find()、replace()

course="Python for Beginners"
print(course.find('P'))  #0
print(course.find('o'))  #4
print(course.find('0'))  #-1
print(course.find('Beginners'))  #11
print(course.replace('Beginners','Absolute Beginners'))  #Python for Absolute Beginners

(七)字符串中是否包含‘Python’?

print('Python'in course)  #True

(八)基础运算

print(10+3)  #13
print(10-3)  #7
print(10*3)  #30
print(10**3)  #1000
print(10/3)  #3.3333333333333335
print(10//3)  #3
print(10%3)  #1

(九)数学函数

四舍五入 round()              绝对值abs()                   .ceil()                    .floor()

print(round(2.9))  #3
print(round(2.4))  #2
print(abs(-2.9))  #2.9
import math              #导入数字模块
print(math.ceil(2.9))  #3
print(math.floor(2.9))  #2

(十)语句

练习1:实现下面文本要求

代码:

is_hot=False
is_cold=False
if is_hot:print('today is hot day')print('drink plenty of water')
elif is_cold:print('today is cold day')print('wear warm clothes')
else:print('today is lovely day')
print('Enjoy your day')

 练习2:实现下面文本要求

solution

price=1000000
has_good_credit = True
if has_good_credit:down_payment=price*0.1
else :down_payment=price*0.2
print(f"down payment is:{down_payment}")
down payment is:100000.0

(十一)逻辑运算符  (and  or  not)

练习

solution

has_high_income=True
has_good_credit=True
if has_high_income and has_good_credit:print("Eligible for loan")

比较运算符(>  <  >=  <=  ==  !=)

练习1

solution

temperature = int(input("temperature is : "))
if temperature > 30:print("it's a hot day")
elif temperature < 10:print("it's a cold day")
else:print("it's a neither hot or cold day")
temperature is :25
it's a neither hot or cold day

练习2

solution

name=input('name: ')
i=len(name)
if i<3:print('name must be at least 3 characters')
elif i>50:print('name can be a maximum of 50 characters')
else:print('name looks good!')

 

实践一  体重单位 磅 和 千克 的转化器

solution

weight=int(input("weight: "))
unit=input("(L)bs or (K)g: ")
if unit.upper()=="L":i=weight*0.45print(f"You are {i} kilos")
elif unit.upper()=="K":i=weight/0.45print(f"You are {i} pounds")
else :print('please input l or k')

效果

(十二)while 循环

简单的例子

i=1
while i<=5:print('*'*i)i+=1
print('Done')
*
**
***
****
*****
Done

实践二 猜谜游戏

secret_number=9
guess_count=0
guess_limit=3
while guess_count<guess_limit:guess=int(input('guess: '))guess_count+=1if guess==secret_number:print('you won!')break
else:print('sorry,you failed!')

结果

实践三 汽车开车

command= ""
started=False
while True:command=input("> ").lower()if command == "help":print('''
start - to start the car
stop - to stop the car
quit - to exit''')elif command== 'start':if started:print('car is already started!')else:started=Trueprint('Car started...')elif command == 'stop':if not started:print('car is already stopped')else:started=Falseprint('Car stopped...')elif command == 'quit':breakelse:print("I don't understand that ...")
> HELPstart - to start the car
stop - to stop the car
quit - to exit> start
Car started...
> start
car is already started!
> stop
Car stopped...
> stop
car is already stopped
> mac
I don't understand that ...
> quitProcess finished with exit code 0

(十三)for 循环

for item in 'Python':print(item)
for item in [1,2,3]:print(item)
for item in ['john','mosh','smith']:print(item)
for item in range(10):print(item)
for item in range(1,10,2):print(item)
P
y
t
h
o
n
1
2
3
john
mosh
smith
0
1
2
3
4
5
6
7
8
9
1
3
5
7
9Process finished with exit code 0

练习  (计算购物车中所有商品的总成本)

prices=[10,20,30]
total=0
for price in prices:total+=price
print(f'total: {total}')#total: 60

(十四)嵌套循环

练习1 打印出多维数组

for x in range(4):for y in range(3):print(f'({x},{y})')
(0,0)
(0,1)
(0,2)
(1,0)
(1,1)
(1,2)
(2,0)
(2,1)
(2,2)
(3,0)
(3,1)
(3,2)

练习2(编写程序打印出下列图像)

solution

for x in [5,2,5,2,2]:print(x*'x')
for x_count in [5,2,5,2,2]:output=""for count in range(x_count):output+='x'print(output)

(十五)列表

names=['john','mosh','shara','mary','lily']
print(names)
print(names[0])
print(names[2:4])
print(names[:])
names[0]='joh'
print(names)
['john', 'mosh', 'shara', 'mary', 'lily']
john
['shara', 'mary']
['john', 'mosh', 'shara', 'mary', 'lily']
['joh', 'mosh', 'shara', 'mary', 'lily']

练习(编写程序找出列表中最大的数)

list=[4,3,5,6,12,1]
max=0
for i in list:if i>=max:max=i
print(max)

(十六)插入  .append()     .insert()

numbers=[5,2,1,5,7,4]
numbers.append(12)
print(numbers)
numbers.insert(0,7)
print(numbers)
[5, 2, 1, 5, 7, 4, 12]
[7, 5, 2, 1, 5, 7, 4, 12]

(十七)删除  del    .remove()   .clear()    .pop()

numbers=[5,2,1,5,7,4]
del numbers[0]#del ,放置索引直接删,不支持赋值语句
print(numbers)
numbers=[5,2,1,5,7,4]
numbers.remove(5)
print(numbers)#remove:直接删成员
numbers.clear()
print(numbers)#clear 全删
numbers=[5,2,1,5,7,4]
numbers.pop()
print(numbers)#不放置索引默认删除末尾值
print(numbers.pop())#pop 可以返回删除值
[2, 1, 5, 7, 4]
[2, 1, 5, 7, 4]
[]
[5, 2, 1, 5, 7]
7

(十八)排序  .sort()    .reverse()

numbers=[5,2,1,5,7,4]
numbers.sort()#升序排序
print(numbers)
numbers.reverse()#降序排序
print(numbers)
[1, 2, 4, 5, 5, 7]
[7, 5, 5, 4, 2, 1]

(十九)查询索引index()   列表中某元素的个数count()

numbers=[5,2,1,5,7,4]
print(numbers.index(1))#查询索引
print(50 in numbers)#判断列表中是否有该元素
print(numbers.count(5))#列表中元素5的个数
2
False
2

(二十)浅拷贝.copy()

numbers=[5,2,1,5,7,4]
num2=numbers.copy()
numbers.append(12)
print(numbers)
print(num2)
[5, 2, 1, 5, 7, 4, 12]
[5, 2, 1, 5, 7, 4]

练习(写一个程序,删除我们列表上的副本(重复项))

numbers=[2,2,5,6,6,5,12,7]
uniques=[]
for number in numbers:if number not in uniques:uniques.append(number)
print(uniques)
[2, 5, 6, 12, 7]

(二十一)矩阵

matrix=[[1,2,3],[4,5,6],[7,8,9]
]
print(matrix)
print(matrix[0][0])
matrix[0][0]=12
print(matrix[0][0])
for row in matrix:for item in row:print(item)
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
1
12
12
2
3
4
5
6
7
8
9

(二十二)元组

元组只读不改,列表可读可改;元组用括号定义

解压缩

numbers=(5,12,7)
x,y,z=numbers
print(x)
print(y)
print(z)
#解压缩同样适用于列表
numbers=[5,12,7]
x,y,z=numbers
print(x)
print(y)
print(z)
5
12
7
5
12
7

(二十三) 字典

customer={"name":"john smith","age":"20","phone":"123456"
}
print(customer)
print(customer['name'])
customer['name']='jock'
print(customer['name'])
customer['email']='13579@qq.com'
print(customer['email'])
{'name': 'john smith', 'age': '20', 'phone': '123456'}
john smith
jock
13579@qq.com

练习1(将输入的号码(数字)翻译成英文打印出来)

 solution

numbers={'0':'zero','1':'one','2':'two','3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine'
}
phone=input('phone: ')
output=""
for i in phone:output+=numbers[i]+" "
print(output)

练习2(表情包转换器1)

message=input('> ')
msg=message.split()
emojis={':)':'												

Python教程笔记----6小时完全入门相关推荐

  1. 简明Python教程笔记(一)

    此文为简明Python教程笔记. 第一部分 介绍 Python特点 简单.易学--伪代码本质 免费开源--FLOSS(自由/开放源码软件) 高层语言 可移植性强--支持多平台 解释性--更易移植 面向 ...

  2. 尚硅谷大数据技术Zookeeper教程-笔记01【Zookeeper(入门、本地安装、集群操作)】

    视频地址:[尚硅谷]大数据技术之Zookeeper 3.5.7版本教程_哔哩哔哩_bilibili 尚硅谷大数据技术Zookeeper教程-笔记01[Zookeeper(入门.本地安装.集群操作)] ...

  3. 廖雪峰Python教程-笔记

    廖雪峰Python教程 学习范围: Python基础 函数 高级特性 函数性编程 模块 面向对象编程 错误,调试和测试 IO编程 笔记: Python的整数没有大小限制 Python 3的字符串使用U ...

  4. 廖雪峰Python教程笔记(一)

    原文链接:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000 感谢廖老师精彩的Pyt ...

  5. 廖雪峰python教程笔记:装饰器

    这是看廖老师python教程的第一个的笔记,因为这是这份教程最难的章节之一,我来来回回看了三遍,终于有所突破,写在这里是为了巩固自己的理解,同时也是希望有错的地方能够得到指正.具体内容见廖雪峰老师的课 ...

  6. Python 爬虫入门的教程(2小时快速入门、简单易懂、快速上手)

    http://c.biancheng.net/view/2011.html 这是一篇详细介绍 Python 爬虫入门的教程,从实战出发,适合初学者.读者只需在阅读过程紧跟文章思路,理清相应的实现代码, ...

  7. python教程笔记(详细)

    本文持续更新- 我的目录 说明 第一部分:python基础知识 0 python风格 0.1 命名风格 0.2 空行与空格 0.2.1 空格和tab 0.2.2 类中的空行问题 1 字符串,strin ...

  8. python教程很详细_Python编程入门教程:从入门到高级,非常详细

    本文的资料和内容是我下载的,觉得非常有用,于是转过来大家瞧瞧: 这里给初学Python的朋友提供一些建议和指导吧.大神请无视, 俗话说:授人以鱼不如授人以渔.所以我这里只是阐述学习过程,并不会直接详细 ...

  9. Python教程:网络爬虫快速入门实战解析

    建议: 请在电脑的陪同下,阅读本文.本文以实战为主,阅读过程如稍有不适,还望多加练习. 网络爬虫简介 网络爬虫,也叫网络蜘蛛(Web Spider).它根据网页地址(URL)爬取网页内容,而网页地址( ...

最新文章

  1. Verilog 流水线加法器
  2. u-boot2013.10引导linux3.10.30记录
  3. EXE和SYS通信(ReadFile WriteFile) 其他方式
  4. 【连载】【FPGA黑金开发板】NIOS II那些事儿--LED实验(四)
  5. XSLT的处理模型(1)
  6. linux live cd 定制,如何创建定制的Ubuntu Live CD或者USB的简易方式
  7. PMP知识点总结—计算题汇总
  8. 如何给Layout文件夹分类
  9. 第7课:郭盛华课程PHP超全局变量
  10. B2C网关支付方案介绍
  11. IceSword 1.18 by PJF
  12. 面对陌生环境,机器人如何像人一样自由穿行?
  13. App逆向——安卓7以上如何安装抓取https的包
  14. 无力回天...机关算尽,还是死在上线之中.............
  15. Linux各种打包和压缩文件命令
  16. windows下测试磁盘读写(HD Tune)
  17. 什么是子网掩码?怎么根据子网掩码得到网络号?
  18. 正常人白手起家挣一千万需要多久?
  19. 【操作教程】EasyNVR视频边缘计算网关硬件如何关闭匿名登录?
  20. pp助手无法连接android,win7系统打不开pp助手怎么办 pp助手无法打开解决方法

热门文章

  1. DFT的基础理论和发展概述
  2. 一个基于Directshow实现的音频播放器,支持歌词显示
  3. 自制PC语音助手(复制代码即可)
  4. UE4 C++ ActionRoguelike开发记录
  5. python输出偶数_python偶数怎么表达 python判断偶数奇数
  6. 图片正常模式混合(透明度混合)公式
  7. PS内容识别填充让图片闹鬼?新升级消灭乱涂乱画,让你刮目相看
  8. 打保龄球(normal)
  9. 一名Web3D开发工程师的Three.js知识总结与学习步骤
  10. 计算机生成目录步骤word,如何在word文档生成目录