博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【377】only one element in a tuple
阅读量:7059 次
发布时间:2019-06-28

本文共 810 字,大约阅读时间需要 2 分钟。

Recently I am doing the assignment of COMP9021. It is too difficult and it is about the Knight and Knave. While I tried to finish this assignment, however I only finnished the code with the testcase Professor Martin gave. I encontered a problem was that if there is only one element in a tuple, actually we need to add a comma.

Examples as follows can help us to understand it.

a = ((2, 3),)b = ((2, 3))c = (2,)d = (2)print(a, b, c, d)print(len(a), len(b), len(c))outputs:((2, 3),) (2, 3) (2,) 21 2 1

Actually, variable a is a tuple with only one element which is (2, 3).

Variable b is a tuple with two elements which is 2 and 3.

So if you want to create a tuple with only one element, you need to add a comma otherwise you will create a different tuple.

转载于:https://www.cnblogs.com/alex-bn-lee/p/10508426.html

你可能感兴趣的文章
搭建rsync服务并同步重要数据
查看>>
MySQL日期与时间戳互转函数
查看>>
图像的二维卷积实现
查看>>
【转载】TypeScript学习笔记——var与let
查看>>
Uninstall from GAC In C# code
查看>>
脚本适用场合
查看>>
xml的sax解析方法
查看>>
咏南开发框架之既支持2层又支持3层开发
查看>>
博客堂Blog开张
查看>>
获得当前时间
查看>>
Spring与web MVC的整合——Spring的应用上下文管理
查看>>
程序员的编辑器——VIM(转)
查看>>
百度编辑器ueditor通过ajax方式提交,不需要事先转义字符的方法(异常:从客户端(xxx)中检测到有潜在危险的 Request.Form 值)...
查看>>
数组按时间(字符串->Date)排序
查看>>
电信网络拓扑图自动布局之曲线布局
查看>>
sqlserver中的循环遍历(普通循环和游标循环)
查看>>
(原)caffe中fine tuning及使用snapshot时的sh命令
查看>>
日期选择器
查看>>
12个Icon图标资源网站
查看>>
C# winform 广告机 网络多媒体发布系统桌面版之三
查看>>