您的位置:首页 > 编程语言 > Python开发

Python Numpy Tutorial: 基本数据类型

2017-05-07 23:11 591 查看
1.

python里面没有对变量“++”的操作,例如: “x++”

2.

用关键字“True”和“False”来表示bool特征,例如:

# -*- coding: utf-8 -*-
"""
Python Version: 3.5
Created on Sun May  7 22:27:34 2017
E-mail: Eric2014_Lv@sjtu.edu.cn
@author: DidiLv
"""

import numpy as np

t = True
f = False

print(type(t),type(f))


输出:

<class 'bool'> <class 'bool'>


3.

python numpy里面没有“||”和“&&”符号,取而代之的为

# -*- coding: utf-8 -*-
"""
Python Version: 3.5
Created on Sun May  7 22:27:34 2017
E-mail: Eric2014_Lv@sjtu.edu.cn
@author: DidiLv
"""

import numpy as np

t = True
f = False

# print(type(t),type(f))
print(t and f)
print(t or f)
print(t != f)


输出为:

False
True
True


4.

# -*- coding: utf-8 -*-
"""
Python Version: 3.5
Created on Sun May  7 22:38:38 2017
E-mail: Eric2014_Lv@sjtu.edu.cn
@author: DidiLv
"""

hello = "hello"
world = "world"

print(hello)
print(hello + " " + world)
print(len(world))
hw12 = "%s %s %d" %(hello, world, 12)
print(hw12)
print("%s, %d" %(hello, 12))


输出:

hello
hello world
5
hello world 12
hello, 12


强力支撑的string功能:注意的是在print语句里“%”是取地址符,然后取地址前不能随便加符号,空格即可

5.

# -*- coding: utf-8 -*-
"""
Python Version: 3.5
Created on Sun May  7 22:48:28 2017
E-mail: Eric2014_Lv@sjtu.edu.cn
@author: DidiLv
"""

s = "hello"
S = "HELLO"
print(s.capitalize())
print(s.upper())
print(S.lower())
print(s.rjust(17))
print(len(s.rjust(17)))
print(S.center(15))
print(S.replace("He", s)) # 注意看字符串中没有相应的替换字符时,输出原有字符串
print(S.replace("HE", s))
print(S.lower().rjust(20).strip()) #strip是删减的意思,这里是删减空格


输出:

Hello
HELLO
hello
hello
17
HELLO
HELLO
helloLLO
hello
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: