人工智能,也就是python语言,是一种高级代码,在程序员的眼里,python就像胶水一样,他可以适应于各种情况,可以以最简单的代码去解决复杂的问题,现阶段python的使用率非常高,知乎就是以python代码编写的网站,而python也可以编写爬取sprider等非常方便的工具,今天达内小编为大家带来,python的基础,希望大家喜欢!

字符串 string
# 定义字符串方式
str = “hello world”
字符串常用方法:
def capitalize(self):
“”“ 首字母变大写 ”“”
def center(self, width, fillchar=None):
“”“ 内容居中,width:总长度;fillchar:空白处填充内容,默认无 ”“”
def count(self, sub, start=None, end=None):
“”“ 子序列个数 ”“”
def decode(self, encoding=None, errors=None):
“”“ 解码 ”“”
def encode(self, encoding=None, errors=None):
“”“ 编码,针对unicode ”“”
def endswith(self, suffix, start=None, end=None):
“”“ 是否以 xxx 结束 ”“”
def expandtabs(self, tabsize=None):
“”“ 将tab转换成空格,默认一个tab转换成8个空格 ”“”
def find(self, sub, start=None, end=None):
“”“ 寻找子序列位置,如果没找到,返回 -1 ”“”
def format(*args, **kwargs): # known special case of str.format
“”“ 字符串格式化,动态参数,将函数式编程时细说 ”“”
def index(self, sub, start=None, end=None):
“”“ 子序列位置,如果没找到,报错 ”“”
def isalnum(self):
“”“ 是否是字母和数字 ”“”
def isalpha(self):
“”“ 是否是字母 ”“”
def isdigit(self):
“”“ 是否是数字 ”“”
def islower(self):
“”“ 是否小写 ”“”
def join(self, iterable):
“”“ 字符串之间以什么连接 ”“”
def ljust(self, width, fillchar=None):
“”“ 内容左对齐,右侧填充 ”“”
def lower(self):
“”“ 变小写 ”“”
def lstrip(self, chars=None):
“”“ 移除左侧空白 ”“”
def partition(self, sep):
“”“ 分割,前,中,后三部分 包含分隔符”“”
def replace(self, old, new, count=None):
“”“ 替换 ”“”
def rsplit(self, sep=None, maxsplit=None):
“”“从右边分割”“”
def rstrip(self, chars=None):
“”“去除右边空格”“”
def split(self, sep=None, maxsplit=None):
“”“ 分割, maxsplit最多分割几次 ”“”
def splitlines(self, keepends=False):
“”“ 根据换行分割 ”“”
def startswith(self, prefix, start=None, end=None):
“”“ 是否起始 ”“”
def strip(self, chars=None):
“”“ 移除两段空白 ”“”
def swapcase(self):
“”“ 大写变小写,小写变大写 ”“”
def translate(self, table, deletechars=None):
“”“
转换,需要先做一个对应表,最后一个表示删除字符集合
”“”
def upper(self):
“”“ 转小写”“”
def zfill(self, width):
“”“方法返回指定长度的字符串,原字符串右对齐,前面填充0.”“”
达内告诉我们,python的代码都很短,更多精彩内容尽在达内