大数据学习Python web开发v大数据学习分享

《Python编程从入门到实践》学习笔记

2018-05-21  本文已影响8人  Python程序媛

《Python编程从入门到实践》学习笔记一:变量命名和字符串

一、变量的命名和使用

变量名只能包含字母、数字和下划线。变量名可以字母或下划线打头,但不能以数字开头,例如,可将变量命名为 message1,但不能将其命名为1_message

变量名不能包含空格,但可使用下划线来分隔其中的单词。例如,变量名 greeting_messag可行,但变量名 greeting message会引发错误。

不要将 Python关键字和函数名用作变量名,即不要使用 Python保留用于特殊用途的单词如 print

在这里还是要推荐下我自己建的Python开发学习群:483546416,群里都是学Python开发的,如果你正在学习Python ,小编欢迎你加入,大家都是软件开发党,不定期分享干货(只有Python软件开发相关的),包括我自己整理的一份2018最新的Python进阶资料和高级开发教程,欢迎进阶中和进想深入Python的小伙伴

附 python关键字和内置函数

关键字:

+—————————————————————–+

False | class | finally | is | return | None | continue

for | lambda | try | True | def | nonlocal | while

and | del | global | not | with | as | elif | if | or | yield

assert | else | import | pass | break | except | in | raise

+—————————————————————–+

内置函数:

+—————————————————————–+

abs() | divmod() | input() | open() | staticmethod()

all() | enumerate() | int() | ord() | str()

any() | eval() | isinstance() | pow() | sum()

basestring() | execfile() | issubclass() | print() | super()

bin() | file() | iter() | property() | tuple()

bool() | filter() | len() | range() | type()

bytearray() | float() | list() | raw_input() | unichr()

callable() | format() | locals() | reduce() | unicode()

chr() | frozenset() | long() | reload() | vars()

classmethod() | getattr() | map() | repr() | xrange()

cmp() | globals() | max() | reversed() | Zip()

compile() | hasattr() | memoryview() | round() | _ import_()

complex() | hash() | min() | set() | apply()

delattr() | help() | next() | setattr() | buffer()

dict() | hex() | object() | slice() | coerce()

dir() | id() | oct() | sorted() | intern()

+—————————————————————–+

二、字符串方法

常用函数,假设有字符串变量name = “ada lovelace”

name.title()以首字母大写的方式显示每个单词—》得到”Ada Lovelace“

name.upper()将字符串改为全部大写 —》得到”ADA LOVELACE“

name.lower()将字符串改为全部小写 —》得到”ada lovelace“

name.rstrip()只去掉字符串末尾的空格

name.lstrip()只去掉字符串开头的空格

name.strip()去掉字符串末尾和开头的空格

上一篇 下一篇

猜你喜欢

热点阅读