python contact函数
时间: 2023-07-07 17:05:26 浏览: 171
"contact" 函数不是 Python 内置函数。也许你指的是 "concat" 函数,它用于连接两个或多个字符串或序列。下面是一个示例:
```
# 连接两个字符串
str1 = "Hello"
str2 = "World"
result_str = str1 + str2
print(result_str) # 输出 "HelloWorld"
# 连接两个列表
list1 = [1, 2, 3]
list2 = [4, 5, 6]
result_list = list1 + list2
print(result_list) # 输出 [1, 2, 3, 4, 5, 6]
```
如果这不是你想要的函数,请提供更多信息以便我可以理解你的需求并提供适当的帮助。
相关问题
pandas contact函数
pandas中的`concat`函数用于将多个数据对象按照指定的轴进行连接。它可以在不同的轴上进行连接,如行轴(axis=0)或列轴(axis=1)。
下面是一个示例:
```python
import pandas as pd
# 创建两个DataFrame对象
df1 = pd.DataFrame({'A': [1, 2, 3],
'B': [4, 5, 6]})
df2 = pd.DataFrame({'A': [7, 8, 9],
'B': [10, 11, 12]})
# 在行轴上连接两个DataFrame对象
result = pd.concat([df1, df2], axis=0)
print(result)
```
输出结果为:
```
A B
0 1 4
1 2 5
2 3 6
0 7 10
1 8 11
2 9 12
```
在这个示例中,我们创建了两个包含相同列的DataFrame对象,并使用`concat`函数在行轴上进行合并。合并后的结果包含了原始DataFrame对象的所有行。
除了行轴上的连接,`concat`函数还可以进行列轴上的连接。你可以通过设置`axis=1`来实现这一点。
希望能对你有所帮助!如果有任何问题,请随时提问。
python函数个人通讯录
以下是一个简单的Python函数个人通讯录的实现:
```python
def add_contact(contacts, name, phone):
"""
添加联系人
"""
contacts[name] = phone
print("联系人添加成功!")
def search_contact(contacts, name):
"""
查找联系人
"""
if name in contacts:
print("{}的电话号码是:{}".format(name, contacts[name]))
else:
print("未找到该联系人!")
def delete_contact(contacts, name):
"""
删除联系人
"""
if name in contacts:
del contacts[name]
print("联系人删除成功!")
else:
print("未找到该联系人!")
def show_all_contacts(contacts):
"""
显示所有联系人
"""
if not contacts:
print("通讯录为空!")
else:
print("所有联系人如下:")
for name, phone in contacts.items():
print("{}的电话号码是:{}".format(name, phone))
def main():
"""
主函数
"""
contacts = {}
while True:
print("欢迎使用个人通讯录!")
print("1.添加联系人")
print("2.查找联系人")
print("3.删除联系人")
print("4.显示所有联系人")
print("5.退出程序")
choice = input("请输入您的选择:")
if choice == "1":
name = input("请输入联系人姓名:")
phone = input("请输入联系人电话:")
add_contact(contacts, name, phone)
elif choice == "2":
name = input("请输入联系人姓名:")
search_contact(contacts, name)
elif choice == "3":
name = input("请输入联系人姓名:")
delete_contact(contacts, name)
elif choice == "4":
show_all_contacts(contacts)
elif choice == "5":
print("感谢使用个人通讯录,再见!")
break
else:
print("输入有误,请重新输入!")
if __name__ == '__main__':
main()
```