Python Numpy Tutorial: 基本数据类型

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值