Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_44340130
Python-100-Days
提交
90d1528f
P
Python-100-Days
项目概览
weixin_44340130
/
Python-100-Days
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Python-100-Days
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
90d1528f
编写于
7月 25, 2018
作者:
骆昊的技术专栏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新了部分代码
上级
e2a7bbde
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
25 deletion
+56
-25
Day01-15/Day01/初识Python.md
Day01-15/Day01/初识Python.md
+36
-3
Day31-35/code/mycal.py
Day31-35/code/mycal.py
+20
-22
未找到文件。
Day01-15/Day01/初识Python.md
浏览文件 @
90d1528f
...
@@ -47,12 +47,14 @@ Linux环境自带了Python 2.x版本,但是如果要更新到3.x的版本,
...
@@ -47,12 +47,14 @@ Linux环境自带了Python 2.x版本,但是如果要更新到3.x的版本,
安装依赖库(因为没有这些依赖库可能在源代码构件安装时因为缺失底层依赖库而失败)。
安装依赖库(因为没有这些依赖库可能在源代码构件安装时因为缺失底层依赖库而失败)。
```
Shell
```
Shell
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
```
```
下载Python源代码并解压缩到指定目录。
下载Python源代码并解压缩到指定目录。
```
Shell
```
Shell
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
xz -d Python-3.6.1.tar.xz
xz -d Python-3.6.1.tar.xz
tar -xvf Python-3.6.1.tar
tar -xvf Python-3.6.1.tar
...
@@ -61,14 +63,38 @@ tar -xvf Python-3.6.1.tar
...
@@ -61,14 +63,38 @@ tar -xvf Python-3.6.1.tar
切换至Python源代码目录并执行下面的命令进行配置和安装。
切换至Python源代码目录并执行下面的命令进行配置和安装。
```
Shell
```
Shell
cd Python-3.6.1
cd Python-3.6.1
./configure --prefix=/usr/local/python3.6 --enable-optimizations
./configure --prefix=/usr/local/python3.6 --enable-optimizations
make && make install
make && make install
```
```
创建软链接,这样就可以直接通过python3直接启动Python解释器。
配置PATH环境变量并使其生效,这需要修改用户主目录下名为.bash_profile的文件。
```
Shell
cd ~
vim .bash_profile
```
```
Shell
# 此处省略上面的代码
PATH=$PATH:/usr/local/python3.6/bin
# 此处省略下面的代码
```
```
Shell
source .bash_profile
```
最后还可以创建一个符号链接(如果不知道为什么也可以暂时不管这个问题啦)。
```
Shell
```
Shell
ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3
ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3
```
```
...
@@ -84,11 +110,13 @@ MacOS也是自带了Python 2.x版本的,可以通过[Python的官方网站](ht
...
@@ -84,11 +110,13 @@ MacOS也是自带了Python 2.x版本的,可以通过[Python的官方网站](ht
在终端或命令行提示符中键入下面的命令。
在终端或命令行提示符中键入下面的命令。
```
Shell
```
Shell
python --version
python --version
```
```
当然也可以先输入python进入交互式环境,再执行以下的代码检查Python的版本。
当然也可以先输入python进入交互式环境,再执行以下的代码检查Python的版本。
```
Python
```
Python
import sys
import sys
print(sys.version_info)
print(sys.version_info)
...
@@ -100,6 +128,7 @@ print(sys.version)
...
@@ -100,6 +128,7 @@ print(sys.version)
可以用文本编辑工具(推荐使用Sublime、Atom、TextMate、VSCode等高级文本编辑工具)编写Python源代码并将其命名为hello.py保存起来,代码内容如下所示。
可以用文本编辑工具(推荐使用Sublime、Atom、TextMate、VSCode等高级文本编辑工具)编写Python源代码并将其命名为hello.py保存起来,代码内容如下所示。
```
Python
```
Python
print('hello, world!')
print('hello, world!')
```
```
...
@@ -108,6 +137,7 @@ print('hello, world!')
...
@@ -108,6 +137,7 @@ print('hello, world!')
切换到源代码所在的目录并执行下面的命令,看看屏幕上是否输出了"hello, world!"。
切换到源代码所在的目录并执行下面的命令,看看屏幕上是否输出了"hello, world!"。
```
Shell
```
Shell
python hello.py
python hello.py
```
```
...
@@ -119,6 +149,7 @@ python hello.py
...
@@ -119,6 +149,7 @@ python hello.py
2.
多行注释 - 三个引号开头,三个引号结尾
2.
多行注释 - 三个引号开头,三个引号结尾
```
Python
```
Python
"""
"""
第一个Python程序 - hello, world!
第一个Python程序 - hello, world!
...
@@ -212,8 +243,9 @@ PyCharm的安装、配置和使用我们在后面会进行介绍。
...
@@ -212,8 +243,9 @@ PyCharm的安装、配置和使用我们在后面会进行介绍。
1. 在Python交互环境中下面的代码查看结果并将内容翻译成中文。
1. 在Python交互环境中下面的代码查看结果并将内容翻译成中文。
```Python
```Python
import this
import this
Beautiful is better than ugly.
Beautiful is better than ugly.
Explicit is better than implicit.
Explicit is better than implicit.
Simple is better than complex.
Simple is better than complex.
...
@@ -238,8 +270,9 @@ PyCharm的安装、配置和使用我们在后面会进行介绍。
...
@@ -238,8 +270,9 @@ PyCharm的安装、配置和使用我们在后面会进行介绍。
2. 学习使用turtle在屏幕上绘制图形。
2. 学习使用turtle在屏幕上绘制图形。
```Python
```Python
import turtle
import turtle
turtle.pensize(4)
turtle.pensize(4)
turtle.pencolor('red')
turtle.pencolor('red')
turtle.forward(100)
turtle.forward(100)
...
...
Day31-35/code/mycal.py
100644 → 100755
浏览文件 @
90d1528f
#!/usr/bin/python3
#!/usr/bin/python3
from
datetime
import
datetime
from
datetime
import
datetime
import
sys
import
sys
...
@@ -7,34 +8,31 @@ def is_leap(year):
...
@@ -7,34 +8,31 @@ def is_leap(year):
return
year
%
4
==
0
and
year
%
100
!=
0
or
year
%
400
==
0
return
year
%
4
==
0
and
year
%
100
!=
0
or
year
%
400
==
0
def
get_days
(
year
,
month
):
days
=
[[
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
],
[
31
,
29
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
]]
return
days
[
is_leap
(
year
)][
month
-
1
]
def
main
():
def
main
():
if
len
(
sys
.
argv
)
>
1
:
if
len
(
sys
.
argv
)
==
3
:
month
=
int
(
sys
.
argv
[
1
])
month
=
int
(
sys
.
argv
[
1
])
year
=
int
(
sys
.
argv
[
2
])
year
=
int
(
sys
.
argv
[
2
])
else
:
else
:
current_date
=
datetime
.
now
()
now
=
datetime
.
now
()
year
=
current_date
.
year
date
=
now
.
date
month
=
current_date
.
month
month
=
now
.
month
year2
=
year
if
month
>=
3
else
year
-
1
year
=
now
.
year
c
=
year2
//
100
m
,
y
=
(
month
,
year
)
if
month
>=
3
else
(
month
+
12
,
year
-
1
)
y
=
year2
%
100
c
,
y
=
y
//
100
,
y
%
100
m
=
month
if
month
>=
3
else
month
+
12
w
=
(
y
+
y
//
4
+
c
//
4
-
2
*
c
+
26
*
(
m
+
1
)
//
10
)
%
7
w
=
y
+
y
//
4
+
c
//
4
-
2
*
c
+
26
*
(
m
+
1
)
//
10
month_words
=
[
w
%=
7
'January'
,
'February'
,
'March'
,
'April'
,
'May'
,
'June'
,
months
=
[
'January'
,
'February'
,
'March'
,
'April'
,
'May'
,
'June'
,
'July'
,
'August'
,
'September'
,
'October'
,
'November'
,
'December'
'July'
,
'August'
,
'September'
,
'October'
,
'November'
,
'December'
]
]
print
(
f
'
{
months
[
month
-
1
]
}
{
year
}
'
.
center
(
20
))
print
(
f
'
{
month
_word
s
[
month
-
1
]
}
{
year
}
'
.
center
(
20
))
print
(
'Su Mo Tu We Th Fr Sa'
)
print
(
'Su Mo Tu We Th Fr Sa'
)
print
(
' '
*
3
*
w
,
end
=
''
)
print
(
' '
*
3
*
w
,
end
=
''
)
total_days
=
get_days
(
year
,
month
)
days
=
[
for
day
in
range
(
1
,
total_days
+
1
):
[
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
],
print
(
f
'
{
day
}
'
.
rjust
(
2
),
end
=
' '
)
[
31
,
29
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
]
][
is_leap
(
year
)][
month
-
1
]
for
day
in
range
(
1
,
days
+
1
):
print
(
str
(
day
).
rjust
(
2
),
end
=
' '
)
w
+=
1
w
+=
1
if
w
==
7
:
if
w
==
7
:
print
()
print
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录