linux c语言isfinite,学习Python第一天,命令很多跟Lin

学习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 "", line 1, in

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]就没有遵守这个规则,返回的是一个空。

(前包括,后不包括)

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值