Python_杂七杂八的知识点

2022-03-01  本文已影响0人  Gakki0725
作者:Gakki

Python 中 append,insert 和 extend 的区别?

list_1 = ["name", "account", "password"]
list_2 = ["test1", "test2"]
list_1.append("111")
list_1.insert(1, "呀哈哈") # 在列表指定位置插入对象
list_1.extend(list_2)

如何删除 Python 数组的值?

list_1 = ["name", "account", "password", "account"]
list_2 = ["test1", "test2"]
list_1.remove("account")
print("列表现在为 : ", list_1)
del_data = list_1.pop(1)
print("列表现在为 : ", list_1)
print("删除的元素为 : ", del_data)
列表现在为 :  ['name', 'password', 'account']
列表现在为 :  ['name', 'account']
删除的元素为 :  password

注: 字典 pop() 方法删除字典给定键 key 所对应的值,返回值为被删除的值。key值必须给出。 否则,返回default值。

len() 函数有什么作用?

operators 中的 is、not 和 in 各有什么功能?

如何将字符串转换为全小写?

data = "This is String Example...Wow!!! yeah~"
print("全部转换为大写:%s" % data.upper())
print("全部转换为小写:%s" % data.lower())
print("将字符串的第一个字母变成大写,其他字母变小写:%s" % data.capitalize())
print("所有单词的首个字母转化为大写,其余字母均为小写:%s" % data.title())
print("检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写:%s" % data.upper().istitle())
print("检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写:%s" % data.title().istitle())
全部转换为大写:THIS IS STRING EXAMPLE...WOW!!! YEAH~
全部转换为小写:this is string example...wow!!! yeah~
将字符串的第一个字母变成大写,其他字母变小写:This is string example...wow!!! yeah~
所有单词的首个字母转化为大写,其余字母均为小写:This Is String Example...Wow!!! Yeah~
检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写:False
检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写:True
上一篇 下一篇

猜你喜欢

热点阅读