learn python the hard way 习题18~25总结

定义函数和调用函数的语法

定义函数

形式:

def functionName(p1,p2):
    statement

other statement

需要注意:

  1. 紧跟者函数定义的代码是否使用了4个空格的缩进?不能多,也不能少
  2. 函数结束的位置是否取消了缩进?

调用函数

形式:
functionname(a1,a2)

UTF-8的相关知识

UTF-8 是 Unicode Transformation Format 8 Bits 的简称,是一种编码规定,其目的在于减少编码时候的文本对内存的浪费。
这是一种压缩编码方式,针对常见字符使用8位,需要的时候再去使用16位或者32位。

在 python3.7 下调用函数

调用函数有两种方式:

  1. from ex25 import *:意思是将所有里面的函数都导入进来,并且在使用的时候不需要添加模块名 ex25.
  2. import ex25:意思是导入 ex25 这个库,.py 是不需要的,因为 Python 知道文件以 .py 结尾。
    ###帮助文档
    在 脚本中,当定义函数时,“”“括起来的句子即为帮助文档,可以在 Python3.7 中用 help(ex25) 或者 python(ex25.break_words)来查看所有函数和单个函数的帮助文档。

逻辑术语

Python 中以 not, and,or 来表示逻辑非,逻辑与,逻辑或。
以 True 和 False 来表示 boolean 的真或假。

原文地址:https://www.cnblogs.com/FBsharl/p/10164439.html

时间: 2024-08-05 21:10:43

learn python the hard way 习题18~25总结的相关文章

learn python the hard way 习题45-制作一个游戏

小白自学python. from sys import exit from random import randint class Scene(object): def enter(self): print "it's no use" exit(1) class Engine(object): def __init__(self,scene_map): self.scene_map = scene_map def play(self): current_scene = self.sce

笨办法学 Python (Learn Python The Hard Way)

最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注释和井号 习题 3: 数字和数学计算 习题 4: 变量(variable)和命名 习题 5: 更多的变量和打印 习题 6: 字符串(string)和文本 习题 7: 更多打印 习题 8: 打印,打印 习题 9: 打印,打印,打印 习题 10: 那是什么? 习题 11: 提问 习题 12: 提示别人

实例:编译Linux内核3.18.25概要

前提: 将CentOS 7上3.10.0-229.el7.x86_64重新编译一个3.18.25内核 自编译安装,按照自己的硬件平台架构编译,能最适合硬件主机的性能 且按照需要编译模块,可以选择自己需要的包编译 [[email protected] tmp]# uname  -a 一.编译前准备工作 1.宿主机系统 本次编译宿主机:VMware Workstation Pro12 上的CentOS 7.0操作系统 2.开发环境(开发工具,开发库),头文件 [[email protected] y

Learn Python the Hard Way--Exercise 46

0. 缘起 <Learn Python the Hard Way>Exercise 46 要求安装四个python package pip, distribute, nose, virtualenv,(原书作者特别提醒: Do not just donwload these packages and install them by hand. Instead see how other people recommend you install these packages and use th

Learn Python From &#39;Head First Python&#39; [3](2) : Pickle

1.the use of 'with open... as ...' 2.the use of pickle(dump and load) for Step1: the 'with open ... as...' is the short format of 'try...except...finally' for Step2: you can store a list with pickle.dump() and get the content again with pickle.load()

Learn Python From &#39;Head First Python&#39; [2] : Sharing

1.publish 2.update print_lol PS: for Step 1. write the code in to a py file. put the py file into a folder named nester. new a py file named 'setup' and the content as below: setup( name = 'nester', version = '1.0.0', py_modules = ['nester'], author

Learn Python From &#39;Head First Python&#39; [1] : The List

1.the concept of List 2. how to define a method of myself 3.how to iterator a list PS: for Step 2,3. it is related with a key word: 'def'. we define a function like below. def function name: XXXXX e.g. list iterator : 1 def print_lol(the_list): 2 for

Learn Python From &#39;Head First Python&#39; [0] : Install

1. download software form the python‘s webset 2. install the python and set the class path 3. verify if the install is correct PS: for Step 2. if you use the default install. then undre the disk C:, there will be a dir like Python34. go to the env se

Learn Python From &#39;Head First Python&#39; [3] : Exception

1.the using of exception 2.file opration import os >>> try: data = open('sketch.txt') for each in data: try: (role,message) = each.split(':') print(role + ' says: ' + message, end='') except ValueError: pass data.close() except IOError: print('fi