前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >学习Python第一天,命令很多跟Lin

学习Python第一天,命令很多跟Lin

作者头像
py3study
发布2020-01-16 15:19:52
5070
发布2020-01-16 15:19:52
举报
文章被收录于专栏:python3

学习Python第二天,看了一天,有点头疼,准备先休息一会,再继续。有一点C语言和Java基础,学起来不是很费劲。学习热情尚好。

学习了dir,math模块,import加载模块,有跟Linux相似的地方。

>>> dir(math) ['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc'] >>> help(math.pow) Help on built-in function pow in module math:

pow(x, y, /) Return x**y (x to the power of y).

模块的加载方式:

>>> from __future__ import division >>> 5/2 2.5 >>> import math >>> help(math) Help on built-in module math:

NAME math

 Python 3 中字符串的连接,3舍弃了``,反向单引号,因为辨识度差。print后面需要加括号().

>>> a=("free") >>> b=1988 >>> print a+'b' SyntaxError: Missing parentheses in call to 'print'. Did you mean print(a+'b')? >>> print a SyntaxError: Missing parentheses in call to 'print'. Did you mean print(a)? >>> print (a+b) Traceback (most recent call last): File "<pyshell#62>", line 1, in <module> print (a+b) TypeError: can only concatenate str (not "int") to str >>> print (a+'b') freeb >>> print (a+`b`) SyntaxError: invalid syntax >>> print (a+str'b') SyntaxError: invalid syntax >>> print (a+str(b)) free1988 >>>

 转义符

"\"

赋值时,“r"表示为原始字符串。字符串里面的内容没有含义

>>> d="c:\news" >>> print (d) c: ews >>> d=r"c:\news" >>> print(d) c:\news >>> e="c:\\news" >>> print e SyntaxError: Missing parentheses in call to 'print'. Did you mean print(e)? >>> print (e) c:\news >>>

input函数,input()

>>> input("input your name:") input your name:python 'python' >>>

input结合print的小程序

print("Hello,World!") name=input("What's your name?") age=input("How old are you?") print("Your name is " + name) print("And you are "+age+" years old.") ten=int(age)+10 print("After ten years,you will be "+ str(ten) +" years old. ")

运行结果。

D:\WPy64-3720\ZZ>python 0515-2.py Hello,World! What's your name?Zoe How old are you?31 Your name is Zoe And you are 31 years old. After ten years,you will be 41 years old.

索引和切片

>>> lang=("study") >>> >>> lang[0] 's' >>> lang.index("d") 3 >>> a=lang[2:4] >>> a 'ud' >>> b=[2:] SyntaxError: invalid syntax >>> b=lang[2:] >>> b 'udy' >>>

序列的切片,一定要左边的数字小于右边的数字,lang[-1:-3]就没有遵守这个规则,返回的是一个空。

(前包括,后不包括)

如果第二个数字大于字符串的长度,得到的返回结果就自动到最大长度位置终止。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/06/05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云开发 CloudBase
云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档