【WIP】Python 基础

创建: 2021/04/19

 

背景:

  本来没法算学的,因为已经实际工作使用很多语言了。之所以开始学,

  原因两点。第一点,最近开始重学算法,虽然说是C但是书上其实算是模拟代码,我几年前学的时候是用C语言去实现的,但是C语言嘛,效率低的一批。所以最近开始用Ruby来实现了,效率直线上升。Ruby也好, JavaScript也罢, 或者Python也算上,其实都差不多,就一脚本语言。Ruby和JavaScript个人都是业务级水平的, 反正要去实现算法而且也差不多,索性多学一个Python, 然后用Python去实现算法。另外这三语言在各种编程测试里面的时间啊内存限制其实一样的,如果看这个的读者是个在校学生,那其实你随便学哪一个就可以了,没必要都学的。第二点,最近英语方面也在抓紧学。想想以前学日语也是,当时新标日就只有初级中级,高级都没出,学完了中级以后就没有后续东西了。所以就开始用日语学各种学科了,语言水平和专业水平都是直线上升的。所以基于自身经验,尽可能多的学一些自己还没有经验的又不太急需的东西。所有打算先从用纯英语学Python开始。

 

用书: [Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming]

2021/04/19 说明: 上面这本书实在太简单了,作为完全啥都不懂的小白可以用,但是其他情况下不怎么推荐。博主是因为oreilly的那本没货才买这本的。但是可能还是会用那本吧。暂时先看着这本好了。可能后面重新做个文档。这本书就当学英语了

推荐这本 [Introducing Python: Modern Computing in Simple Packages (English Edition)]

 

这篇博文的作用: 老规矩, 个人文档

 

Getting Started
 Installation  
brew install pyenv
# ... some setting steps
pyenv install 3.9.4
# pyenv global 3.9.4 # set a version u like to global to replace the system one
pyenv local 3.9.4

python --version

Thats all about installation and version control. The instruction from the original book is too verbose and difficult to practise.

Just use a text ediftor whatever you like. Personally, i strongly recommend Atom.

   
Variables and Simple Data Types
 Variables

 Rules and conventions

 ● Variable names can contain only letters, numbers and underscores.

    Cannot starts with a number.

 ● Spaces are not allowed in variable names.

 ● Avoid using Python keywords as variable names.

 ● Variable names should be short but descriptive, that is, concise.

String 

 ● both single and double quotes are acceptable

case
title

 

name.title()

 

 

upper  
lower  
 embeding strings

 

f"...{...}..."

 

 ● needs python larger than or equal to 3.6

 ● <=3.5 needs to use format

"...{.}...{.}...".format(s1, s2)

 

 

 

   
   
   
   
   
   
   
   
   
Lists
   
   
   
   
   
   
   
   
   
   
   
if, while
   
   
   
   
   
   
   
   
   
   
   
Dictionaries
   
   
   
   
   
   
   
   
   
   
   
Functions
   
   
   
   
   
   
   
   
   
   
   
Classes
   
   
   
   
   
   
   
   
   
   
   
Files
   
   
   
   
   
   
   
   
   
   
   
Exceptions
   
   
   
   
   
   
   
   
   
   
   
Testing
   
   
   
   
   
   
   
   
   
   
   
posted @ 2021-04-19 08:00  懒虫哥哥  阅读(63)  评论(0编辑  收藏  举报