美文网首页
2018-12-31 python第二天:python的字符串

2018-12-31 python第二天:python的字符串

作者: 鑫耶 | 来源:发表于2019-01-01 01:19 被阅读0次

基本字符串类型
类:
数字 int
python3 里面 不管多大的数字都是int python2里面 长数字属于long

a = 123
v = a.bit_length()
print(v)

#   int 将字符串转换成数字(转化成十进制)
b = "123"
print(int(b))

# 将0011按照二进制转化成十进制
c = "0011"
print(int(c , base=2))


字符串

a2 = "sHenZhen"

# 全部转化为大写
v2 = a2.upper()
print(v2)
# SHENZHEN

# 全部转化为小写
v3 = a2.capitalize()
print(v3)
# Shenzhen

# 将字符串前后进行填充
v4 = a2.center(20,"&")
print(v4)
#&&&&&&sHenZhen&&&&&&

# 子字符集在字符中出现的次数
v5 = a2.count("en")
print(v5)
# 2

# 将字符串的占位符替换成指定的值
a3 = "i am {name} , age {age1}"
print(a3)
# i am {name} , age {age1}
v6 = a3.format(name = "cheungxin" , age1 = 24)
print(v6)
# i am cheungxin , age 24

作业
1.执行python脚本的两种方式: python
python 1.py
2,简述位和字节的关系
8位一个字节,计算机以字节为单位,存储以位为单位

3,简述区别:
ascill 00000000
& 00000001
unicode 0000000000000+
& 0000000000001
中 0010001110001
utf-8 能用多少表示就用多少
& 00000001
中 0010001110001

# range 范围
# a = range(0,10)
# for item in a:
#     print(item)

test = input("请输入一个数字>>>")
print("test")
l = int(test)
for item in range(0,l):
    print(item)





相关文章

  • python基础知识(3)

    python字符串 python转义字符 python字符串运算符 python字符串格式化 python格式化操...

  • python count()方法详解

    Python count()方法 Python 字符串 描述 Python count() 方法用于统计字符串里某...

  • python字符串格式化符号与内建函数资料表

    python字符串格式化符号: Python 的字符串内建函数 Python 的字符串常用内建函数如下:

  • Python notes(2/3)

    目录 一,python 字符串 二,Python列表(List) 三,Python 元组 四,Python字典 五...

  • 字符串

    一、Python 2 和Python 3 最大的区别就是字符串 Python 2 中的字符串是byte的有序序列 ...

  • Python常用语法二

    Python 字符串操作和文件操作以及其它Python能力补充 Python字符串操作 in和not in: 'x...

  • 字符串操作方法

    Python3字符串 Python访问字符串中的值 Python中的字符串用单引号(')或双引号(")括起来,同时...

  • python字符串相关函数

    Python3字符串 Python访问字符串中的值 Python中的字符串用单引号(')或双引号(")括起来,同时...

  • 2018-09-28自学习资料

    Python3字符串 Python访问字符串中的值 Python中的字符串用单引号(')或双引号(")括起来,同时...

  • 字符串内置函数

    Python3字符串 Python访问字符串中的值 Python中的字符串用单引号(')或双引号(")括起来,同时...

网友评论

      本文标题:2018-12-31 python第二天:python的字符串

      本文链接:https://www.haomeiwen.com/subject/wbcblqtx.html