脚本小子_python数据类型代码

#!/usr/local/bin/python3
# coding:utf-8
# format格式
# x = 4
# y = 4
# z = x + y
# 格式化,输出整形
# print("z is {0:d}".format(z))
# 格式化,输出浮点型,并保留两位小数点
# print("z is {0:.2f}".format(z))

# 一、数值
# 整数、浮点数、长整数、复数
# 1、整数
# x = 2
# print("x is {0}".format(x))
# print("x**4 is {0}".format(x**4))
# print("{0}".format(int(8.3)/int(2.7)))

# 2、浮点数
# print("{0:.3f}".format(8.3/2.7))

# 3、内置数学库 math
# import math
# 查看math有哪些方法
# print dir(math)
# 开根号
# x = 4
# x2 = math.sqrt(4)
# print("4 开根号: {0}".format(x2))

# 二、字符串
# 字符串可以包含在单引号、双引号、3 个单引号或 3 个双引号之间
# print("单引号:{},双引号:{},3单引号:{}".format('hello world',"hello world",'''hello world'''))
# 打印字符串可以使用的方法
# print dir("hello")
# 1、分割与连接
# split 分割 split(分割符[,分割数])
# 默认按照分割符全部分割
# print "hello=world=haha".split('=')
# 只分割1个
# print "hello=world=haha".split('=',1)
# join 连接 一般操作列表、元组
# print("{}".format(" ".join(['hello','world'])))
# print("{}".format(",".join(('hello','world'))))

# 2、字符去掉与替换
# 去掉不必要字符,strip两边,lstrip左边,rstrip右边
# 默认是去掉空格
# print(" hello world ".strip())
# 去掉指定字符
# print("!hello world!".strip('!'))
# replace替换字符 replace(string1,string2,num),按照次数num,把字符string1替换成string2
# print("hello#world#haha".replace('#',' '))
# print("hello#world#haha".replace('#',' ',1))

# 3、字母大小写问题
# lower小写 upper大写 capitalize首字母大写
print("HellO WoRld".lower())
print("HellO WoRld".upper())
print("HellO WoRld".capitalize())
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值