美文网首页
零基础学Python 读《编程小白的第一本 Python 入门

零基础学Python 读《编程小白的第一本 Python 入门

作者: 像苏 | 来源:发表于2020-02-17 23:20 被阅读0次

图书地址(点击查看)

第一章 为什么选择 Python?

1、精简:学习最核心的关键知识;

2、理解:运用类比、视觉化的方法来理解这些核心知识;

3、实践:构建自己的知识体系之后,再通过实践去逐渐完善知识体系。

学习方法

第二章 现在就开始

1.安装Python

从 Python 的官方网站下载对应的Python 版本(点击查看)(速度很慢😓)

(win系统务必记得勾上Add Python 3.X to PATH)

2.安装pycharm

pycharm官方下载地址(点击查看)(速度略慢,需要耐心点)

第三章 变量与字符串

3.1 开始学习编程

别发懒,上手敲代码

3.2 变量

Python 对大小写敏感, “a” 和 “A” 会是两个不同的变量

    a = 12

3.3 print()

1.打印变量前需要先赋值

2.用英文标点

file = open('/Users/yourname/Desktop/file.txt','w')

 file.write('hello world')

查看文件路径的方法是,Windows 用户用资源管理器打开桌面上的一个文件,查看路径。Mac 用户打开终端 terminal,然后把桌面上的某个文件拖拽进去就可以查看到路径。

3.驼峰式命名,小驼峰式(例子:yourName)

大驼峰式和帕斯卡命名相同(例子:YourName)

3.4 字符串

字符串就是'任何在这之间的文字',"任何在这之间的文字",'''三引号用于过长的文字,可以随意换行'''

1.字符串可以相加

what_he_dose = ' plays ' 

his_instrument = ' guitar' 

his_name = 'Robert Johnson' 

artist_intro = his_name + what_he_dose + his_instrument 

 print(artist_intro)

2.变量可以使'字符串',整数,浮点数(小数),布尔值(True,False)布尔值首字母大写,不同类型之间不能够合并,需要转换成同类型才可以,查看变量类型可以用type()

num = 1 

string = '1' 

num2 = int(string) 

print(num + num2)

3.字符串可以相乘

word = 'a looooooooog word' 

num = 12 

string = 'bang!' 

total = string * (len(word) - num) 

print(total)

len()可以得到变量的长

4.字符串的分片与索引

字符串是从0开始计数,可以通过 string[x] 的方式进行索引、分片

name = 'My Name is Mike' 

print(name[0]) 

print(name[-4]) 

print(name[11:14]) 

print(name[11:15]) 

print(name[5:]) 

print(name[:5])

[]方括号里面的数值,包前不包后

word = 'friends' 

find_the_evil_in_your_friends = word[0] + word[2:4] + word[-3:-1] 

print(find_the_evil_in_your_friends)

url = 'http://ww1.site.cn/14d2e8ejw1exjogbxdxhj20ci0kuwex.jpg' 

file_name = url[-10:] 

print(file_name)

5.字符串的方法

看到这个标题有些懵,书上解释是面向对象的方法,把汽车car理解成对象,汽车的功能drive理解为方法,写法:car.drive()

phone_number = '1386-666-0006' 

hiding_number = phone_number.replace(phone_number[:-4],'*'*9) 

print(hiding_number)

6.字符串格式化符

这个是填空,用.format()处理

(1)当前面的花括号里面没有内容时,需要和format括号里面的词数量相等

(2)前面花括号里面有单词时,后面format括号里是(单词 = '需要填的词')

(3)format括号里面的词可以按字符串的切片数索引

print('{} a word she can get what she {} for'.format('With','came')) 

print('{preposition} a word she can get what she {verb} for'.format(preposition = 'With',verb = 'came')) 

print('{0} a word she can get what she {1} for'.format('With','came'))

format括号里面也可以是变量

city = input('write down the name of city:') 

url = 'http://apistore.baidu.com/microservice/weather?citypinyin={}'.format(city)

相关文章

网友评论

      本文标题:零基础学Python 读《编程小白的第一本 Python 入门

      本文链接:https://www.haomeiwen.com/subject/lsrnxhtx.html