`

Python基础教程之第5章 条件, 循环和其他语句

阅读更多
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
#Chapter 5 条件, 循环和其他语句
#5.1 print和import的更多信息
#对于很多应用程序来说, 使用logging模块记日志比print语句更合适
#5.1.1 使用逗号输出
#可以看到, 每隔参数之间都自动插入了一个空格符
>>> print 'Age:',42
Age: 42
>>> 1,2,3
(1, 2, 3)
#print的参数并不像我们预期那样构成一个元组
>>> print 1,2,3
1 2 3
>>> print (1,2,3)
(1, 2, 3)
>>> name='Gumby'
>>> salution='Mr.'
>>> greeting='Hello,'
>>> print greeting, salution, name
Hello, Mr. Gumby
>>> greeting='Hello'
>>> print greeting, ',', salution, name
Hello , Mr. Gumby
>>> print greeting + ',', salution, name
Hello, Mr. Gumby
#如果在结尾处加上逗号,那么接下来的语句会与前一语句在同一行打印(只在脚本中起作用,在交互式Python会话中无效)
print 'Hello,',
print 'world!'
#输出Hello, world!
#5.1.2 import语句
#import somemodule
#from somemodule import somefunction
#from somemodule import somefunction, anotherfunction, yetanotherfunction
#from somemodule import *
#为模块提供别名
>>> import math as foobar
>>> foobar.sqrt(4)
2.0
#为函数提供别名
>>> from math import sqrt as foobar
>>> foobar(4)
2.0
#给不同模块中的同名函数提供别名
#from module1 import open as open1
#from module2 import open as open2
#5.2 赋值魔法
#5.2.1 序列解包(sequence unpacking)
>>> x, y, z = 1, 2, 3
>>> print x, y, z
1 2 3
>>> x, y = y, x
>>> print x, y, z
2 1 3
>>> values = 1,2,3
>>> values
(1, 2, 3)
>>> x,y,z=values
>>> x
1
>>> y
2
>>> z
3
>>> scoundrel={'name':'Robin', 'girlfriend':'Marion'}
>>> key, value = scoundrel.popitem()
>>> key
'girlfriend'
>>> value
'Marion'
>>> x,y,z = 1,2

Traceback (most recent call last):
  File "<pyshell#31>", line 1, in <module>
    x,y,z = 1,2
ValueError: need more than 2 values to unpack
>>> x,y,z=1,2,3,4

Traceback (most recent call last):
  File "<pyshell#32>", line 1, in <module>
    x,y,z=1,2,3,4
ValueError: too many values to unpack
#Python 3.0 中有另外一个解包的特性
#a,b,rest*=[1,2,3,4]
#rest的结果将会是[3,4]
#5.2.2 链式赋值
#x=y=somefunction
#等效于
#y=somefunction
#x=y

#5.2.3 增量赋值(augmented assignment)
>>> x=2
>>> x += 1
>>> x *= 2
>>> x
6
>>> fnord = 'foo'
>>> fnord += 'bar'
>>> fnord *= 2
>>> fnord
'foobarfoobar'
#语句块: 缩排的乐趣
#5.4 条件和条件语句
# False None 0 "" '' () [] {} 会被解释器看做假
>>> True
True
>>> False
False
>>> True == 1
True
#标准的布尔值为False(0)和True(1)
>>> False == 0
True
>>> True + False + 42
43
#bool函数可以用来(和list, str以及tuple类似)转换其他值
>>> bool('I think, therefore I am')
True
>>> bool(42)
True
>>> bool('')
False
>>> bool(0)
False
>>> bool([])
False
>>> bool(())
False
>>> bool({})
False
#5.4.2 条件执行和if语句
>>> name = raw_input('What is your name? ')
What is your name? Gumby
>>> if name.endswith('Gumby'):
...     print 'Hello, Mr. Gumby'
...
Hello, Mr. Gumby
#5.4.3 else子句
>>> name = raw_input('What is your name? ')
What is your name? Jon
>>> if name.endswith('Gumby'):
...     print 'Hello, Mr. Gumby'
... else:
...     print 'Hello, stranger'
...
Hello, stranger
#5.4.4 elif子句
>>> num = input('Enter a number: ')
Enter a number: 0
>>> if num > 0:
...     print 'The number is positive'
... elif num < 0:
...     print 'The number is negative'
... else:
...     print 'The number is zero'
...
The number is zero
#5.4.5 嵌套代码块
>>> name = raw_input('What is your name? ')
What is your name? Mrs. Gumby
>>> if name.endswith('Gumby'):
...     if name.startswith('Mr.'):
...             print 'Hello, Mr. Gumby'
...     elif name.startswith('Mrs.'):
...             print 'Hello, Mrs. Gumby'
...     else:
...             print 'Hello, Gumby'
... else:
...     print 'Hello, stranger'
...
Hello, Mrs. Gumby
#链式比较运算
#比较对象的时候可以使用内建的cmp函数
>>> age=10
>>> 0<age<100
True
>>> age=-1
>>> 0<age<100
False
#相等运算符
>>> "foo" == "foo"
True
>>> "foo" == "bar"
False
>>> "foo" = "foo"
  File "<stdin>", line 1
SyntaxError: can't assign to literal
#同一性运算符
#避免将is运算符用于比较类似数值和字符串这类不可变值.
>>> x=y=[1,2,3]
>>> z=[1,2,3]
>>> x == y
True
>>> x == z
True
>>> x is y
True
>>> x is z
False
>>>
>>> x is z
False
>>> x = [1,2,3]
>>> y = [2,4]
>>> x is not y
True
>>> del x[2]
>>> y[1]=1
>>> y.reverse()
>>> x == y
True
>>> x is y
False
#in: 成员资格运算符
>>> name = raw_input('What is your name? ')
What is your name? Jonathan
>>> if 's' in name:
...     print 'Your name contains the letter "s".'
... else:
...     print 'Your name does not contain the letter "s".'
...
Your name does not contain the letter "s".
>>> "alpha" < "beta"
True
>>> 'FnOrd'.lower() == 'Fnord'.lower()
True
>>> [1,2] < [2,1]
True
>>> [2,[1,4]]<[2,[1,5]]
True
#布尔运算符

>>> number = input('Enter a number between 1 and 10: ')
Enter a number between 1 and 10: 8
>>> if number <= 10:
...     if number >=1:
...             print 'Great!'
...     else:
...             print 'Wrong!'
... else:
...     print 'Wrong!'
...
Great!
>>> number = input('Enter a number between 1 and 10: ')
Enter a number between 1 and 10: 6
>>> if number <= 10 and number >= 1:
...     print 'Great!'
... else:
...     print 'Wrong!'
...
Great!
>>> number = input('Enter a number between 1 and 10: ')
Enter a number between 1 and 10: 11
>>> if 1 <= number <= 10:
...     print 'Great!'
... else:
...     print 'Wrong!'
...
Wrong!
>>> name = raw_input('Please enter your name: ') or '<unknown>'
Please enter your name:
>>> name
'<unknown>'
#短路逻辑和条件表达式
#类似C和Java中的三元运算符
>>> name = 'Jon'if True else 'Jack'
>>> name
'Jon'
>>> name = 'Jon'if False else 'Jack'
>>> name
'Jack'
#5.4.7 断言
>>> age = 10
>>> assert 0 < age < 100
>>> age = -1
>>> assert 0 < age < 100
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError
#条件后可以添加逗号和字符串,用来解释断言
>>> age = -1
>>> assert 0 < age < 100, 'The age must be realistic'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError: The age must be realistic
#5.5 循环
#5.5.1 while循环
>>> x=1
>>> while x <= 100:
...     print x
...     x +=1
...
1
2
3
...
100
>>> x
101

>>> name = ''
>>> while not name:
...     name = raw_input('Please enter your name: ')
...
Please enter your name:
Please enter your name:
Please enter your name: Jon
>>> print 'Hello, %s!' % name
Hello, Jon!
>>> name = ''
>>> while not name or name.isspace():
...     name = raw_input('Please enter your name: ')
...
Please enter your name:
Please enter your name:
Please enter your name: Chan
>>> print 'Hello, %s!' % name
Hello, Chan!
>>> while not name.strip():
...     name = raw_input('Please enter your name: ')
...
>>> name = ''
>>> while not name.strip():
...     name = raw_input('Please enter your name: ')
...
Please enter your name:
Please enter your name:
Please enter your name: Kingston
>>> print 'Hello, %s!' % name
Hello, Kingston!

#5.5.2 for循环
>>> words=['this', 'is', 'an', 'ex', 'parrot']
>>> for word in words:
...     print word
...
this
is
an
ex
parrot
>>> numbers = [0,1,2,3,4,5,6,7,8,9]
>>> for number in numbers:
...     print number
...
0
1
2
3
4
5
6
7
8
9
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
#如果能使用for循环,就尽量不用while循环
#当需要迭代一个巨大的序列时,xrange会比range更高效
>>> for number in range(1,5):
...     print number
...
1
2
3
4
#5.5.3 循环遍历字典元素
>>> d={'x':1, 'y':2, 'z':3}
>>> for key in d:
...     print key, 'corresponds to', d[key]
...
y corresponds to 2
x corresponds to 1
z corresponds to 3
>>> for key, value in d.items():
...     print kye, 'corresponds to', value
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
NameError: name 'kye' is not defined
>>> for key, value in d.items():
...     print key, 'corresponds to', value
...
y corresponds to 2
x corresponds to 1
z corresponds to 3
>>>


#5.5.4 一些迭代工具
#并行迭代
>>> names = ['anne', 'beth', 'george', 'damon']
>>> ages = [12, 45, 32, 102]
>>> for in in range(len(names)):
	
SyntaxError: invalid syntax
>>> for i in range(len(names)):
	print names[i], 'is', ages[i], 'year old'

	
anne is 12 year old
beth is 45 year old
george is 32 year old
damon is 102 year old
>>> for i in range(len(names)):
	print names[i], 'is', ages[i], 'years old'

	
anne is 12 years old
beth is 45 years old
george is 32 years old
damon is 102 years old
>>> zip(names, ages)
[('anne', 12), ('beth', 45), ('george', 32), ('damon', 102)]
>>> for name, age in zip(names, ages):
	print name, 'is', age, 'years old'

	
anne is 12 years old
beth is 45 years old
george is 32 years old
damon is 102 years old
>>> zip(range(5), xrange(100000000))
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)]
#在索引上迭代
>>> strings = ['I am xxx', 'I like losing my face', 'Say goodbye']
>>> for string in strings:
	index = strings.index(string) # Search for the string in the list of strings
	strings[index]='[censored]'

	
>>> strings
['[censored]', '[censored]', '[censored]']
>>> strings = ['I am xxx', 'I like losing my face', 'Say goodbye']
>>> for string in strings:
	if 'xxx'in strings:
		index = strings.index(string) # Search for the string in the list of strings
		strings[index]='[censored]'

		
>>> strings
['I am xxx', 'I like losing my face', 'Say goodbye']
>>> strings = ['I am xxx', 'I like losing my face', 'Say goodbye']
>>> for string in strings:
	if 'xxx' in string:
		index = strings.index(string) # Search for the string in the list of strings
		strings[index]='[censored]'

		
>>> 
>>> string
'Say goodbye'
>>> strings
['[censored]', 'I like losing my face', 'Say goodbye']
>>> ['I am xxx', 'I like losing my face', 'Say goodbye']
['I am xxx', 'I like losing my face', 'Say goodbye']
>>> index = 0
>>> for string in strings:
	if 'xxx' in string:
		strings[index]='[censored]'
index += 1
SyntaxError: invalid syntax
>>> index = 0
>>> for string in strings:
	if 'xxx' in string: strings[index]='[censored]'
	index += 1

	
>>> strings
['[censored]', 'I like losing my face', 'Say goodbye']
>>> ['I am xxx', 'I like losing my face', 'Say goodbye', 'xxx is a sensitive word']
['I am xxx', 'I like losing my face', 'Say goodbye', 'xxx is a sensitive word']
>>> for index, string in enumerate(strings):
	if 'xxx' in string:
		strings[index]='[censored]'

		
>>> strings
['[censored]', 'I like losing my face', 'Say goodbye']
>>> strings = ['I am xxx', 'I like losing my face', 'Say goodbye', 'xxx is a sensitive word']
#enumerate函数可以在提供索引的地方迭代索引-值对.
>>> for index, string in enumerate(strings):
	if 'xxx' in string:
		strings[index]='[censored]'

		
>>> strings
['[censored]', 'I like losing my face', 'Say goodbye', '[censored]']

#翻转和排序迭代
>>> sorted([4,3,6,8,3])
[3, 3, 4, 6, 8]
>>> sorted('Hello, world!')
[' ', '!', ',', 'H', 'd', 'e', 'l', 'l', 'l', 'o', 'o', 'r', 'w']
>>> list(reversed('Hello, world'))
['d', 'l', 'r', 'o', 'w', ' ', ',', 'o', 'l', 'l', 'e', 'H']
>>> ''.join(reversed('Hello, world!'))
'!dlrow ,olleH'

#5.5.5 跳出循环
#break
>>> from math import sqrt
>>> for n in range(99, 0, -1);
SyntaxError: invalid syntax
>>> for n in range(99, 0, -1):
	root = sqrt(n)
	if root == int(root):
		print n
		break

	
81
# continue
# while True/break习惯用法
>>> word = 'dummy'
>>> while word:
	word = raw_input('Please enter a word: ')
	# 处理word:
	print 'The word was ' + word

	
Please enter a word: first
The word was first
Please enter a word: second
The word was second
Please enter a word: 
The word was 

>>> word = raw_input('Please enter a word: ')
Please enter a word: first
>>> while word:
	print 'The word was ' + word
	word = raw_input('Please enter a word: ')

	
The word was first
Please enter a word: second
The word was second
Please enter a word: 

>>> while True:
	word = raw_input('Please enter a word: ')
	if not word: break
	print 'The word was ' + word

	
Please enter a word: first
The word was first
Please enter a word: second
The word was second
Please enter a word: 
#5.5.6 循环中else子句
#原始方案
from math import sqrt
break_out = False
for n in range(99, 81, -1):
	root = sqrt(n)
	if root == int(root):
		break_out = True
		print n
		break

if not break_out:
	print "Didn't find it!"

		
#结果Didn't find it!

#改进方案
from math import sqrt
for n in range(99, 81, -1):
	root = sqrt(n)
	if root == int(root):
		print n
		break
else:
	print "Didn't find it!"
#结果Didn't find it!

#列表推导式(list comprehension)--轻量级循环

>>> [x*x for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
#可以和if子句联合使用
>>> [x*x for x in range(10) if x % 3 == 0]
[0, 9, 36, 81]
>>> [(x,y) for x in range(3) for y in range(3)]
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
>>> 
>>> result=[]
>>> for x in range(3):
	for y in range(3):
		result.append((x,y))

		
>>> result
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]

>>> girls=['alice', 'bernice', 'clarice']
>>> boys=['chris', 'arnold', 'bob']
>>> [b+'+'+g for b in boys for g in girls if b[0] == g[0]]
['chris+clarice', 'arnold+alice', 'bob+bernice']

#更优方案
>>> girls = ['alice', 'bernice', 'clarice']
>>> boys = ['chris', 'arnold', 'bob']
>>> letterGirls={}
>>> for girl in girls:
	letterGirls.setdefault(girl[0], []).append(girl)

	
>>> print [b+'+'+g for b in boys for g in letterGirls[b[0]]]
['chris+clarice', 'arnold+alice', 'bob+bernice']
>>> letterGirls
{'a': ['alice'], 'c': ['clarice'], 'b': ['bernice']}


#5.7 三人行 pass, del 和 exec

#5.7.1 什么都没发生

>>> name = 'Bill Gates'
>>> if name == 'Ralph Auldus Melish':
...     print 'Welcome!'
... elif name == 'Enid':
...     pass
... elif name == 'Bill Gates':
...     print 'Access Denied'
...
Access Denied

#5.7.2 使用del删除
>>> scoundrel = {'age':42, 'first name':'Robin', 'last name':'of Locksley'
>>> robin = scoundrel
>>> scoundrel
{'last name': 'of Locksley', 'first name': 'Robin', 'age': 42}
>>> robin
{'last name': 'of Locksley', 'first name': 'Robin', 'age': 42}
>>> scoundrel = None
>>> scoundrel
>>> print scoundrel
None
>>> robin
{'last name': 'of Locksley', 'first name': 'Robin', 'age': 42}
>>> x = 1
>>> y = x
>>> x=1
>>> del x
>>> x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>> x = ['Hello', 'world']
>>> y = x
>>> y[1]='Python'
>>> x
['Hello', 'Python']
>>> del x
>>> y
['Hello', 'Python']

#5.7.3 使用exec和eval执行和求值字符串
# exec 在 Python 3.0 中是一个函数而不是语句
>>> exec "print 'Hello, world!'"
Hello, world!
>>> from math import sqrt
>>> exec "sqrt=1"
>>> sqrt(4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable

#命名空间,或称为作用域(scope)
#可以通过in <scope> 来实现, 其中的<scope>就是起到放置代码字符串命名空间作用的字典
>>> from math import sqrt
>>> scope={}
>>> exec 'sqrt = 1' in scope
>>> sqrt(4)
2.0
>>> scope ['sqrt']
1
>>> len(scope)
2
>>> scope.keys()
['__builtins__', 'sqrt']
# eval--求值字符串
>>> eval(raw_input("Enter an arithmetic express: "))
Enter an arithmetic express: 6 + 18 * 2
42
>>> scope={}
>>> scope['x']=2
>>> scope['y']=3
>>> eval('x * y', scope)
6
>>> scope = {}
>>> exec 'x=2' in scope
>>> eval('x*x', scope)
4
>>>

#5.8 小结
#打印--print语句可以用来打印由逗号隔开的多个值. 如果语句以逗号结尾,随后的print语句会在同一行内接续打印
#导入--可以用as对模块或函数提供别名
#赋值--通过 序列解包 和 链式赋值 功能, 多个变量可以一次性赋值, 通过 增量赋值 可以原地改变变量
#块--块是通过缩排使语句成组的一种方法. 块可以在条件以及循环语句中使用,也可以在函数和类中使用
#条件--几个条件可以串联使用if/elif/else. 还有一个变体叫做条件表达式,形如a if b else c.
#断言--断言简单来说就是肯定某事(布尔表达式)为真, 也可在它后面跟上这么认为的原因.
#循环--可以使用continue语句跳过块中的其他语句然后继续下一次迭代, 或使用break语句跳出循环
#    还可以选择在循环结尾加上else子句, 当没有执行循环内部的break语句时便会执行else子句中的内容.
#列表推导式--是看起来像循环的表达式.通过它, 可以从旧列表中产生新的列表, 对元素应用函数, 过滤掉不需要的元素,等等.
#pass, del, exec 和 eval 语句. pass语句什么都不做, 可以作为占位符使用. del语句用来删除变量(名称),或数据结构的一部分, 但是不能用来删除值.
#    exec语句用与执行Python程序相同的方式来执行字符串. 内建的eval函数对字符串中的表达式进行求值并返回结果.

#5.8.1 本章的新函数
#chr(n)		返回序数n所代表的字符的字符串(0<=n<=256)
#eval(source[, globals[, locals]])	将字符串作为表达式计算,并且返回值
#enumerate	产生用于迭代的(索引,值)对
#ord(c)		返回单字符字符串的int值
#range([start,] stop[, step])	创建整数的列表
#reversed(seq)	产生seq中值的反向副本, 用于迭代
#sorted(seq[, cmp][, key][, reverse])	返回seq中值排序后的列表副本
#xrange([start,] stop[, step]) 创建xrange对象用于迭代
#zip(seq1, seq2,...)	创建用于并行迭代的新序列

分享到:
评论

相关推荐

    Python基础教程05第五章条件循环和其他语句ppt课件.ppt

    Python基础教程05第五章条件循环和其他语句ppt课件.ppt

    Python基础教程-05第五章条件、循环和其他语句.pptx

    Contents 目录 print,import 赋值魔法 语句块 条件和条件语句 循环 列表推导式 三人行 小结 Python基础教程--05第五章条件、循环和其他语句全文共65页,当前为第2页。 print和import 01 Python基础教程--05第五章...

    python中的ch表示什么-Python基础教程Ch5-条件、循环和其他语句.pdf

    python中的ch表⽰什么_Python基础教程Ch5-条件、循环和其 他语句 第5章 条件、循环和其他语句 第5章 条件、循环和其他语句 5.1print和import的更多信息 print语句可以同时打印多个表达式,只需要⽤逗号分隔即可,...

    Python基础教程(第2版.修订版)

    第5章 条件、循环和其他语句 第6章 抽象 第7章 更加抽象 第8章 异常 第9章 魔法方法、属性和迭代器 第10章 充电时刻 第11章 文件和素材 第12章 图形用户界面 第13章 数据库支持 第14章 网络编程 第15章 ...

    python基础入门教程.docx

    循环语句和条件语句的相关操作 6.函数的应用 7.了解数组的属性类型。 8.掌握有关数组的基本操作。 9.掌握 NumPy 矩阵与其通用函数。 1.输入与输出格式 程序分析: Print()是输出语句。 可以使用str.format(填充的...

    千峰python课件笔记+源码 (凯哥)

    千锋python基础教程:1、第一个python程序与数据存储 '千锋python基础教程:2、print&input;与变量和运算符' 千锋python基础教程:3、字符串与循环中的while '千锋python基础教程:4、布尔&list;与条件循环语句与...

    Python基础教程(第3版)中文高清无水印+数据源代码

    列表和元组........................................23第 3 章 使用字符串 .......................................41第 4 章 当索引行不通时 ...............................54第 5 章 条件、循环及其他语句 ...

    赵璐python教程答案-《Python语言程序设计教程》赵璐著【摘要书评在线阅读】-苏宁 .pdf

    2.2 标识符及命名规则 2.3 变量与赋值语句 2.4 数据的输⼊与输出 2.5 数值 2.6 字符串 2.7 混合运算和类型转换 本章⼩结 课后习题 第3章 程序流程控制 3.1 条件表达式 3.2 选择结构 3.3 循环结构 3.4 random库的基本...

    计算机软件开发编程语言Python培训教程(从零开始学编程)-课程2和3判断循环语句函数.pptx

    Python 基础课程 Lecture 2、3 从零开始学编程系列 计算机软件开发编程语言Python培训教程(从零开始学编程)-课程2和3判断循环语句函数全文共39页,当前为第1页。 目录 1 2 3 4 5 计算机软件开发编程语言Python培训...

    python案例教程钱毅湘-Python案例教程.pdf

    python案例教程钱毅湘_Python案例教程 章 Python语⾔基础 1.1 知识要点 1.1.1 程序设计概述 1.1.2 Python语⾔概述 1.1.3 Python程序的格式框架 1.1.4 常量和变量 1.1.5 Python数据类型 1.1.6 基本运算 1.1.7 Python...

    智普教育Python培训就业班 150多集Python基础+就业视频教程.txt

    智普教育python培训就业班python随堂视频教程 01 Python简介.flv 智普教育python培训就业班python随堂视频教程 02 分支语句if基础.flv 智普教育python培训就业班python随堂视频教程 03 分支语句与逻辑关系表达式....

    Python基础编程全教程+实践案例

    非常适合Python入门的全教程,Python 基础教程 2、 Python概述 2.1 认识Python 2.2 Python的安装 2.3 集成开发环境Pycharm 3、 第一个Python程序 3.1 Python程序执行原理 3.2 Python程序文件执行 3.3 Python...

    尚硅谷Python核心基础

    任务5: 尚硅谷_Python基础_05_环境变量13:12 任务6: 尚硅谷_Python基础_06_Path环境变量15:36 任务7: 尚硅谷_Python基础_07_进制介绍21:30 任务8: 尚硅谷_Python基础_08_文本和字符集17:04 任务9: 尚硅谷_...

    python基础入门全套教程.docx

    循环语句和条件语句的相关操作 6.函数的应用 7.了解数组的属性类型。 8.掌握有关数组的基本操作。 9.掌握 NumPy 矩阵与其通用函数。 1.输入与输出格式 程序分析: Print()是输出语句。 可以使用str.format(填充的...

    Python基础教程详解(第二十五课)-初探list.doc

    Python基础教程详解 【第25课】 初探list 上节课课程里的例子写在程序里发生了点错误。当时写这个代码片段时,心里假想着这 是在一个函数的内部,所以用了return语句。如果没有把它放在函数里,那return的话 就会...

    老男孩第三期Python全栈开发视频教程 零基础系统学习Python开发视频+资料

    ├─(70) 05 python s3 day50 django模板之控制语句if和for循环.avi ├─(71) 06 python s3 day50 django模板之标签tag补充.avi ├─(72) 07 python s3 day50 django模板之自定义filter和simple_tag.avi ├─(73) 08...

    python的重点和难点-Python教学大纲.doc.pdf

    python的重点和难点_Python教学⼤纲.doc Python教学⼤纲.doc 《Python快速编程⼊门》课程教学⼤纲 (课程英⽂名称) 课程编号:201700310011 学 分:5学分 学 时:59学时 (其中:讲课学时41 上机学时:18) 先修...

    Python语言程序设计PPT课件.zip

    第5章 Python函数与模块。有些经常用到的能实现特定功能的代码块,我们总是不希望每次用到时都重写一遍,甚至不希望复制一遍,但又想重复使用。Python里这些经常重用的代码块以函数(Function)的形式被定义,每一次...

    Python3入门指南_v2.4.pdf

    三、Python基础语法学习 30 3.1 编写第一个Python程序 30 3.2 Python中单行与多行注释语法 31 3.3 python输出功能基本语法:print() 32 3.4 python输入功能基本语法:input() 34 3.5 Python标识符与关键字 34 3.6 ...

Global site tag (gtag.js) - Google Analytics