Python学习记录博客是本人记录学习python3过程中的一些记录和过程,日后也可以帮助自己温习。
python优点:
1.Python入门简单,功能强大,适用性强;
2.开发效率高,第三方库强大且多;
3.Python无需考虑底层细节;
4.可移植性,跨平台;
5.可扩展性;
6.可嵌入性,Pthon可嵌入到C/C++程序中;
python缺点:
1.速度慢,Python比C慢很多,比java也慢一点;
2.代码不能加密,源码是明文;
3.线程不能利用多 CPU 问题;
python版本2和3的区别:
1.python3支持中文,不需要特别声明字符编码;
2.一些语法变化;
3.库名变化;
4.去除库中某些冗余功能
变量定义的规则:
1.变量名只能是字母、数字或下划线的任意组合;
2.变量名的第一个字符不能是数字;
3.以下关键字不能声明为变量名:
[‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘exec‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘not‘, ‘or‘, ‘pass‘, ‘print‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]
ASCII码:
交互式输入
python2有raw_input和input,使用input输入时,只能输入变量名或者数字
python3只有input,默认输入的变量是string类型
Tab补全模块
vim /usr/local/python/lib/python2.7/site-packages/tab.py
# python startup file import sys import readline import rlcompleter import atexit import os # tab completion readline.parse_and_bind(‘tab: complete‘) # history file histfile = os.path.join(os.environ[‘HOME‘], ‘.pythonhistory‘) try: readline.read_history_file(histfile) except IOError: pass atexit.register(readline.write_history_file, histfile) del os, histfile, readline, rlcompleter
猜年龄(数字)游戏
#!/usr/bin/env python#_*_coding:utf-8_*_‘‘‘ * Created on 2016/10/10 19:29. * @author: Chinge_Yang.‘‘‘ age = 27count = 0 for i in range(10): if count < 3: guess_num = int(input("Input your guess number:")) if age == guess_num: print("Congraturation,you are right!") break elif age > guess_num: print("You guess it smaller than it!") else: print("You guess it bigger than it!") count += 1 else: continue_confirm = input("Do you want to continue(y|n):") if continue_confirm == "y": count = 0 else: print("bye") break