本文共 2937 字,大约阅读时间需要 9 分钟。
一:基础知识
1、python是动态解释性的强类型定义语言
2、编译器:cpython pypy 是python 的未来
3、Notepad++:
4、开发工具:pycharm
二:重点笔记
1、注释
2、配置模板:
在pycharm中,view------toolbar------工具------editor------code style-----file and code templates-----python script
3、变量规则 :
4、常量: 用大写,例如 PIE=3.1415926
5、 字符编码(烽火狼烟)
GB2312------GBK------GB18030-------Unicode(万国码)-------UTF-8
ASCII1个字节,Unicode占2个字节,UTF-8: 英文占1个字节,中文占2个字节。
6、格式化输出
三:示例
1、Hello World
第一个python程序
1 name ="你好,世界"2 3 print(name)
2、格式化输出 printf
1 name=input("name:") 2 age=int(input("age:")) #强制转化数据类型 3 print(type(age),type(str(age))) #打印数据类型 4 job=input("job:") 5 salary=input("salary:") #薪酬 6 7 info=''' 8 -------- Info Of %s -------- 9 Name:%s10 Age:%d11 Job:%s12 Salary:%s13 '''%(name,name,age,job,salary)14 15 print(info)
1 name=input("name:") 2 age=input("age:") 3 4 job=input("job:") 5 salary=input("salary:") #薪酬 6 7 8 info=''' 9 -------- Info Of {_name} --------10 Name:{_name}11 Age:{_age}12 Job:{_job}13 Salary:{_salary}14 '''.format(_name=name,_age=age,_job=job,_salary=salary)15 16 print(info)
3、猜年龄的程序
1 user_of_age=23 2 3 ''' 4 count=0 5 while count<3: #while循环实现 6 guess_of_age=int(input("age:")) 7 if user_of_age==guess_of_age: 8 print("Yes,You Get It!") 9 break 10 elif user_of_age>guess_of_age:11 print("Think bigger....")12 else:13 print("Think smaller....")14 count+=115 else:16 print("Sorry,you have tried too much time...Fuck Off!")17 '''18 19 20 for i in range(3): #for循环实现21 guess_of_age=int(input("age:"))22 if user_of_age==guess_of_age:23 print("Yes,You Get It!")24 break #break 后 就不执行后面的else25 elif user_of_age>guess_of_age:26 print("Think bigger....")27 else:28 print("Think smaller....")29 else:30 print("Sorry,you have tried too much time...Fuck Off!")
1 user_of_age=23 2 3 count=0 4 while count<3: #while循环实现 5 guess_of_age=int(input("name:")) 6 if user_of_age==guess_of_age: 7 print("Yes,You Get It!") 8 break #结束整个循环 9 elif user_of_age>guess_of_age:10 print("Think bigger....")11 else:12 print("Think smaller....")13 count+=114 if count==3:15 countine_confirm=input("Do You Want To Keep Guessing...?(break is n,countine is enter)") #是否继续猜下去16 if countine_confirm !="n":17 count=0
转载地址:http://xrtnmu.baihongyu.com/