1.第一个python程序(在pycharm中运行的,感觉还不错)

  注释:

    当行注释:#被注释内容

    多行注释:'''  被注释内容 '''

2.变量

(1) 自己理解的定义(仅供参考): 为了存储数据以便反复调用的自定义合法标识符(存于内存中)。

比如:name = “congcong”   #name即为一个变量。

 (2)    变量定义的规则:

    <1>变量名只能是字母、数字、或下划线的任意组合。

    <2>变量名的第一个字符不能是数字。

    <3>关键字不能声明为变量名。

      包括['and’,'as','assert'(宣称),'break','class','continue','def','if','elif','else','for','except','finaly',

'exec'(执行程序),'form','global','import','in','is','lambda'(匿名程序),'not','or','pass','print','raise'(增加),

'return','try','while','with','yield'(收率)]。

3.常量的表示

  字母必须大写,且不能修改,否则会出错。

  例如:  PHR = 3

4.字符编码

   (1) python解释器在加载 .py文件中的代码时,会对内容进行编码(默认是ASCII码)

  (2) ASCII码(美国标准信息交换代码)是基于拉丁字母的一套电脑编码系统,主要用于显示现代英语和其他西欧语言,

其最多只能用8位来表示(即一个字节,2**8=256),所以,ASCII码最多只能表示255个字符。如下图(素材来源于网上):

  (3)字符编码发展史:

    ASCII码 ——1980年,GB2312,支持7千多汉字——1995年,GBK1.0,支持2万多汉字——2000年,GB18030,支持2万7千多汉字

—— Unicode,统一为2bytes(字节),由于有争议,接着另开发了utf-8——utf-8,支持中英文,英文1个字母为1byte,而中文一个汉字为3bytes。

5.用户交互程序(如无特殊说明,以下python代码均是在pycharm中运行过的,可用的) 

 #congcong for huangYuTing
import getpass #导入getpass模块,将密码设为不可见
_usename = 'congcong' #预存用户名
_password = 'huangyuting' #预存用户名密码
usename = input("usename:") #用户输入用户名
password = input("password:") #用户输入密码
if _usename == usename and _password == password: #表判断,两个条件均成立时继续
print('Welcome user {name} login...'.format(name = usename)) #.format()获取用户名
else:
print('Invalid usename or password')

6.if...else判断结构(含while) 

 #congcong for huangYuTing
age_of_erha = 21 count = 0
while count < 3:
guess_age = int(input('Guess age:'))
if guess_age == age_of_erha:
print('You are right!')
break
elif guess_age > age_of_erha:
print('Think smaller.')
else :
print('Think bigger...')
count += 1
if count == 3:
print('Do you want to continue....')
Is_continue = input('continue:')
if Is_continue != 'n':
count = 0
#else:

7.while and for 循环

 #congcong for huangYuTing
'''
for i in range(0,15,2):#从 0 开始,15结束,每次相差 2
print('number',i)
''' '''
age_of_erha = 21
for i in range(4):
guess_age = int(input('Guess age:'))
if guess_age == age_of_erha:
print('You are right!')
break
elif guess_age > age_of_erha:
print('Think smaller.')
else :
print('Think bigger...')
else:
print('You have tried too many times....')
''' # continue的使用
'''
for i in range(0,20,2):
if(i > 7):
print('congcong',i)
else:
continue #跳出本次循环,继续下次循环,而break是结束循环
print('Hello')
'''
#多重for循环
for i in range(0,8,1):#小于8,不包含8
print('hello...........',i)
for n in range(0,6,1):
print('world',n)
if n > 3:
break #结束最近的循环
#多重循环打印结果如下:
 hello........... 0
world 0
world 1
world 2
world 3
world 4
hello........... 1
world 0
world 1
world 2
world 3
world 4
hello........... 2
world 0
world 1
world 2
world 3
world 4
hello........... 3
world 0
world 1
world 2
world 3
world 4
hello........... 4
world 0
world 1
world 2
world 3
world 4
hello........... 5
world 0
world 1
world 2
world 3
world 4
hello........... 6
world 0
world 1
world 2
world 3
world 4
hello........... 7
world 0
world 1
world 2
world 3
world 4

 

最新文章

  1. blur和click事件的先后顺序问题
  2. Robot Framework--07 变量的声明、赋值及其使用
  3. MongoDB 入门之基础 DDL
  4. Unity3D 插件大全
  5. linux笔记:RPM软件包管理-源码包管理
  6. PowerMock与EasyMock的应用(转)
  7. Latex之CJK中文书签乱码[转]
  8. 基于NodeJs的网页爬虫的构建(一)
  9. muduo网络库学习笔记(10):定时器的实现
  10. Pasha and String(思维,技巧)
  11. Centos6.3不能使用yum install安装gcc编辑器解决办法
  12. PAT (Advanced Level) 1097. Deduplication on a Linked List (25)
  13. foreach底层机制
  14. Oracle 12C 新特性之非分区表转分区表online clause(不停业务+索引有效)
  15. 兼容ie浏览器的placeholder的几种方法
  16. Tomcat启动一闪而过
  17. 关于使用Ajax请求json数据,@RequestMapping返回中文乱码的几种解决办法
  18. [Ubuntu]修改文件夹及所有子文件夹权限
  19. Mac下如何用SSH连接远程Linux服务器及Linux一些常用操作命令,更新中.....
  20. wxWidgets 和 QT 之间的选择

热门文章

  1. TCP网络编程-----客户端请求连接服务器、向服务器发数据、从服务器接收数据、关闭连接
  2. 调用本地摄像头拍照(H5和画布)
  3. 基于 socket.io 的 AI 服务 杂谈
  4. 【次小生成树】bzoj1977 [BeiJing2010组队]次小生成树 Tree
  5. IRP的同步
  6. SAP的这三款CRM解决方案,您能区分清楚么
  7. JavaScript(五)语句
  8. 异常笔记--java编程思想
  9. ScheduledThreadPoolExecutor详解
  10. mysqlfront提示过期解决方式