二. Python基础(2)--语法】的更多相关文章

二. Python基础(2)--语法 1.实现一个简单的登录系统 '''# 形式1 n = 1 while n < 4:     name = input("请输入姓名\n")     if name == "Arroz":         print("Welcome!")         exit()     else:         print("Wrong name!")         n += 1'''  …
一. Python基础(1)--语法 1. 应用程序 1.1 什么是计算机(Computer)? 组成 ①运算器 arithmetic unit; ※ Arithmetic unit and control unit are collectively called as CPU. ②控制器 control unit; ③存储器 memory unit; ·内部存储器 (内存) internal memory/internal storage; also called: main memory (…
二十二. Python基础(22)--继承 ● 知识框架   ● 继承关系中self的指向 当一个对象调用一个方法时,这个方法的self形参会指向这个对象 class A:     def get(self):         self.say()       def say(self):         print('AAAAA')   class B(A):     def say(self):         print('BBBBB')   b = B() b.get() # BBBBB…
十二. Python基础(12)--生成器 1 ● 可迭代对象(iterable) An object capable of returning its members one at a time. Examples of iterables include all sequence types (such as list, str, and tuple) and some non-sequence types like dict and file and objects of any clas…
六. Python基础(6)--语法 1 ● Python3中, Unicode转字节的方法 print(bytes("李泉", encoding = 'utf-8')) print("李泉".encode("utf-8")) b'\xe6\x9d\x8e\xe6\xb3\x89'   print(bytes("李泉", encoding = 'gbk')) print("李泉".encode("…
五. Python基础(5)--语法 1 ● break结束的是它所在的循环体, continue是让它所在的循环体继续循环 # 打印: 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 for i in range(1, 10): print(i , end = ' ') for i in range(10, 20):      print(i , end = ' ')      break # break是结束它所在的循环体   2 ● 打印: 1 1…
四. Python基础(4)--语法 1 ● 比较几种实现循环的代码 i = 1 sum = 0 while i <= 10: # 循环10-1+1=10次     sum += i     i += 1 print(sum)   sum = 0 for i in range(1, 11): # 循环11-1=10次     sum += i print(sum)   i = 0 sum = 0 while True:     i += 1     if i <=10:         sum…
三. Python基础(3)--语法 1. 字符串格式化的知识补充 tpl = "我是%s,年龄%d,学习进度100%" %('Arroz',18) print(tpl) # 会提示:ValueError: incomplete format# 占位符只有格式化时才有意义   msg = "我是%s,年龄%d,学习进度100%" print(msg) # 结果:我是%s,年龄%d,学习进度100%   # 如果想要格式化输出字符串,同时又想要打印%,需要写两个% m…
本篇主要介绍Python中一些基础语法,其中包括:标识符.关键字.常量.变量.表达式.语句.注释.模块和包等内容. 1. 标识符和关键字 1.1 标识符 标识符是变量.常量.函数.属性.类.模块和包等指定的名称,Python语言中标识符的命名规则如下: (1)区分大小写,例Name与name是两个不同的标识符: (2)标识符首字母可以是下划线“_”或字母,但不能是数字: (3)标识符除首字母外的其它字符,可以是下划线“_”.字母和数字: (4)关键字不作为标识符: (5)Python内建函数不能…
Python第二节 基础语法和数据类型 Python编码 python3默认情况下源码文件以UTF-8编码, 字符串均为unicode字符串.同时也可以通过# -*- coding: cp-1252 -*-这样类似的代码进行源码编码的变更. Python标志符 第一个字符必须是字母或者下划线"_", 绝对不能是数字或其他特殊字符. 其他字符: 任意什么都行 可以使用中文做变量名 标识符对大小写敏感 Python关键字 关键字禁止被用作任何标识符名称. 可通过标准库的keyword模块查…