Python 字符串 find() 方法Python 字符串方法实例单词 "welcome" 在文本中的什么位置?txt = "Hello, welcome to my world."x = txt.find("welcome")print(x)完整实例:txt = "
Python 字符串 expandtabs() 方法Python 字符串方法实例将制表符大小设置为 2 个空格:txt = "H\te\tl\tl\to"x = txt.expandtabs(2)print(x)完整实例:txt = "H\te\tl\tl\to"x
Python 字符串 endswith() 方法Python 字符串方法实例检查字符串是否以标点符号 (.) 结尾:txt = "Hello, welcome to my world."x = txt.endswith(".")print(x)完整实例:txt =
Python 字符串 encode() 方法Python 字符串方法实例对字符串进行 UTF-8 编码:txt = "My name is Ståle"x = txt.encode()print(x)完整实例:txt = "My name is Ståle"x = txt
Python 字符串 count() 方法Python 字符串方法实例返回值 "apple" 在字符串中出现的次数:txt = "I love apples, apple are my favorite fruit"x = txt.count("apple")print(
Python 字符串 center() 方法Python 字符串方法实例打印单词 "banana",占用 20 个字符,并使 "banana" 居中:txt = "banana"x = txt.center(20)print(x)完整实例:txt = "banana"x
Python 字符串 casefold() 方法Python 字符串方法实例将字符串设为小写:txt = "Hello, And Welcome To My World!"x = txt.casefold()print(x)完整实例:txt = "Hello, And Wel
Python 字符串 capitalize() 方法Python 字符串方法实例大写这句话的第一个字母:txt = "hello, and welcome to my world."x = txt.capitalize()print (x)完整实例:txt = "hel
Python zip() 函数Python 内建函数实例把两个元组连接起来:a = ("Bill", "Steve", "Elon")b = ("Gates", "Jobs", "Musk")x = zip(a, b)完整实例:a = ("Bill", "Steve", "Elon
Python vars() 函数Python 内建函数实例返回名为 Person 的对象的 __dict__ 属性:class Person: name = "Bill" age = 19 country = "USA"x = vars(Person)完整实例:class
Python type() 函数Python 内建函数实例返回这些对象的类型:a = ('apple', 'banana', 'cherry')b = "Hello World"c = 55x = type(a)y = type(b)z = type(c)完整实例:a = ('ap
Python tuple() 函数Python 内建函数实例创建包含水果名的元组:x = tuple(('apple', 'banana', 'cherry'))完整实例:x = tuple(("apple", "banana", "cherry"))print(x)定义和
Python super() 函数Python 内建函数实例创建一个将从另一个类继承所有方法和属性的类:class Parent: def __init__(self, txt): self.message def printmessage(self):
Python sum() 函数Python 内建函数实例将所有项添加到一个元组中,并返回结果:a = (1, 2, 3, 4, 5)x = sum(a)完整实例:a = (1, 2, 3, 4, 5)x = sum(a)print(x)定义和用法sum()
Python str() 函数Python 内建函数实例把数字 3.5 转换为字符串:x = str(3.14)完整实例:x = str(3.14)print(x)定义和用法str() 函数将指定的值转换为字符串。语法str(object,