name = input('what is your name?')if name.endswith('zd'): print("hello panzidong") name = input('what is your name?')if name.endswith('zd'): print("hello panzidong")else: print("hello other") num = input('Enter a number:')if…
条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= 18: print('your age is', age) print('adult') 根据Python的缩进规则,如果if语句判断是True,就把缩进的两行print语句执行了,否则,什么也不做. 也可以给if添加一个else语句,意思是,如果if判断是False,不要执行if的内容,去把else执行…
From:http://learnpythonthehardway.org/book/ex37.html 1. with X as Y: pass 1.1 yield 2. exec 2.1 namespace 3. lambda 3.1 map 3.2 map and reduce 4. raise KEYWORD DESCRIPTION EXAMPLE and Logical and. True and False == False as (1) Part of the with-as st…
转自:https://learnxinyminutes.com/docs/python/ # Single line comments start with a number symbol. """ Multiline strings can be written using three "s, and are often used as comments """ ####################################…
This tutorial is available as a short ebook. The e-book features extra content from follow-up posts on various Python best practices, all in a convenient, self-contained format. All future updates are free for people who purchase it. Preliminary fluf…
Python’s handling of default parameter values is one of a few things that tends to trip up most new Python programmers (but usually only once). What causes the confusion is the behaviour you get when you use a “mutable” object as a default value; tha…
引言 1 列表推导式 records = [json.loads(line) for line in open(path)] 这是一种在一组字符串(或一组别的对象)上执行一条相同操作(如json.loads)的简洁方式.在一个打开的文件句柄上进行迭代即可获得一个由行组成的序列.现在,records对象就成为一组Python字典了. {u'a': u'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko)…
python入门(11)条件判断和循环 条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= 18: print 'your age is', age print 'adult' 根据Python的缩进规则,如果if语句判断是True,就把缩进的两行print语句执行了,否则,什么也不做. 也可以给if添加一个else语句,意思是,如果if判断是False,…
初识PYTHON Python(英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/), 是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum(吉多·范罗苏姆)于1989年发明,第一个公开发行版发行于1991年.Python是纯粹的自由软件, 源代码和解释器CPython遵循 GPL(GNU General Public License)协议.Python具有丰富和强大的库.它常被昵称为胶水语言,能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结…
条件判断和循环 条件判断 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= 18: print 'your age is', age print 'adult' 根据Python的缩进规则,如果if语句判断是True,就把缩进的两行print语句执行了,否则,什么也不做. 也可以给if添加一个else语句,意思是,如果if判断是False,不要执行if的内容,去把…