Python学习笔记开篇

已经快30岁了,中专学历,不会什么技术,因为好吃懒做最喜欢的就是吃肉睡觉。

每次想学习技术如PhotoShop,绘声绘影,PHP,易语言,按键精灵都只是3分钟热血。

今天我想在业余时间学习Python,在博客园记录学习的重点笔记,立下Flag,一定要改变自己。

用了大概一个星期的时间学习了3天金角大王的Python的全栈开发的前三课。

回忆如下:

2.x = 默认编码 =ASSIC =不支持
3.x = 默认编码 =UNICODE =默认支持中文

python 3 vs 2
1。 默认支持中文
2. 不兼容2.x
3. 核心语法调整,更易学
4. 新特性默认只在3.x上有

环境变量和JAVA一样可以设置快速启动python

变量的命名规则
1. 要具有描述性
2. 变量名只能_,数字,字母组成,不可以是空格或特殊字符(#?<.,¥$*!~)
3. 不能以中文为变量名(可以用但是不建议用)
4. 不能以数字开头
5. 保留字符是不能被使用

注:Python没有常量  所有的量都是变量  方便区分我们给常量设置为全部大写字母 如:CHANGLIANG

关于Python的垃圾回收机制的问题。Python用了引用计数的方法,每有一个指针引用了一个变量,计数就+1,取消引用则-1。

当某块变量的引用计数为0时,它就自动地被回收了。Python可以用del手动回收垃圾。

字符编码GB2312 gbk1.0 gb18030 big5(台湾) unicode(万国码) UTF-8(unicode 的扩展集)

 

注释
单行注释 用#
多行注释用三个单引号或三个双引号 '''被注释的内容'''

基础语法与Hello World

print("Hello World!")
print("Alex")
print("JinXing")

name = "Alex Li"
x = 3 
y = 4 

z = x * y #运行5分钟 =12 

print("x乘以y=", z  ) 

print("z=", z  ) 

z = 5*8 
print("z=", z  ) 

print = 3 
print(print)
Hello World

用户输入

death_age = 80 


name = input("your name:")
age = input("your age:")  #input 接受的所有数据都是字符串,即便你输入的是数字,但依然会被当成字符串来处理

print( type(age) )


#int integer =整数  把字符串转成int,用int(被转的数据)
#str string =字符串 把数据转成字符串用str(被转的数据)
print("Your name:",name)
#print("You can still live for ",  death_age - int(age)," years ....")
print("You can still live for " +  str(death_age - int(age)) +" years ....")
用户交互

if判断猜年龄

age_of_princal = 56 



guess_age = int(   input(">>:") )
'''
if guess_age == age_of_princal then

    print("yes")
else 
    print("no ")
'''

if guess_age == age_of_princal:
    print("Yes,you got it..")
elif guess_age > age_of_princal:
    print("shoud try samller..")
else:
    print("try bigger ...")
IF判断猜年龄

声明编码

#coding:utf-8

print("我爱北京")
设置编码

if elif判断成绩

score = int(input("score:"))


if score > 90:
    print("A")
elif score > 80:
    print("B")
elif score > 70:
    print("C")
elif score > 50:
    print("D")
else:
    print("")
    
    
if elif判断成绩

强制缩进  官方推荐4个空格缩进

官方不建议Tab缩进 winodws与linux兼容有问题

缩进级别必须保持一致

 

posted on 2017-08-27 15:07  王羿贺  阅读(154)  评论(0)    收藏  举报