python学习小结01

python

 

1.python %取余运算符

 

2.幂运算符:

》》》2**3

8

>>>pow(2,3)

8

 

3.函数就想可执行特定功能的小程序,标准函数称为内建函数

4.abs 绝对值函数

>>>abs(-10)

10

>>>round(1.0/2.0) 取整数

1.0  

 

5.floor, 人的年龄32.9岁, 取整数32,因为还没到33  ????不能直接使用

 

 >>>import math     导入模块math,floor为模块函数

>>>math.floor(32.9)

32.0

>>> int(math.floor(222.2))  转换为整数

222

6.from模块import 函数,

>>> from math import  sqrt

>>> sqrt(9)

3.0

 

7.sqrt函数 开平方计算

>>>>from math import sqrt

>>>>sqrt(4)

2.0

 

8.回到_future_     未来模块

 

9.python不区分单双引号

 

10.

>>> "Let\'s go!"

"Let's go!"

>>> 

11.

 >>> raw_input("raw_input: ")
 >>> raw_input: abc
 >>> input("Input: ")
 >>>Input: “abc”

 

12.\\反斜线标准 单双引号为字符串,而不是字符串结算标识

 

13.拼接字符串:像进行运算符一样拼接

>>> "Hello ," +"word!"

'Hello ,word!'

>>> x="Hello,"

>>> y="word!"

>>> x+y

'Hello,word!'  打印出来仍显示在python代码中状态

>>> 

>>> print(x+y)  使用print输出后

Hello,word!

>>> 

 

14. str 转换字符串函数

   repr创建一个字符串

>>> print repr("Hello,word!")

'Hello,word!'

>>> print repr(10000L)

10000L

>>> print str("Hello,word!")

Hello,word!

>>> print repr(10000L)

10000L

>>> 

repr(x)功能也可以用`x`反引号实现

>>> temp=42

>>> print "The temp is"+ temp

 

Traceback (most recent call last):

  File "<pyshell#12>", line 1, in <module>

    print "The temp is"+ temp    报错因为不能将字符串和数字相加

TypeError: cannot concatenate 'str' and 'int' objects

>>> temp=42

>>> print "The temp is" + `temp`

The temp is42

>>> print "The temp is" + repr(temp)

The temp is42

>>> print "The temp is "+ str(temp)

The temp is 42

>>>   通过反引号 和repr/str将数字转换层字符转所以可以相加

 

15.

长字符串:非常长字符串跨多行时 使用三个双引号,可以在字符串之间使用双引号及单引号,而不需要反斜杠进行转义

"" "" ""

 

原始字符串:r前缀    可以理解为原始字符串中放入任何字符

如 路径

>>> '\n'

 

'\n'

 

>>> print '\n'

 

>>> r'\n'

 

'\\n'

 

>>> print r'\n'     输出字符串 \n

 

\n

print r'\n'        输出换行符\n

 

 

unicode字符串:u前缀

 

 

数据结构:通过某种方式组织在一起的数据元素的集合

python中最基本的数据结构就是序列,序列中每个元素被分配一个序号(元素的位置),

即索引,第一个为0

 

python:包含6中内建序列

1.列表

2.元组

3.字符串

4.xrange对象(范围对象)

5.unicode字符串

6.buffer缓存对象

 

 

container容器序列

 

16索引--元素的位置 重0递增

>>> x="hello"    通过索引获取元素

>>> x[0]

'h'

>>> x[3]

'l'

>>> x[1]

'e'

>>> 

 

posted @ 2018-08-31 16:43  蘑菇慢慢  阅读(88)  评论(0)    收藏  举报