python - 在 swift 和 python 中从相同的返回类型获得不同的结果

标签 python swift python-3.x swift3

<分区>

我是 Python 的新手。

When I have created a simple object in swift:-

let one = 7.0
let two = 2.0
var three = one / two
print(three)
let first = 7
let second = 2
let third = CGFloat(first/second)
print(third)

输出结果是:- 3.5 和 3.0

I am creating simple objects in python. Using Python in the terminal.

>>> 7/2.
3.5
>>> float(7/2)
3.0)

输出结果是:- 3.5 和 3.0

为什么是 7/2。自动读取整数以 float 。当我这样声明两个不同的整数时:-

>>> a = 7 
>>> b = 2
>>> c = a / b.

显示错误。语法无效。

Python 如何在 7 月 2 日生成自动结果。并得到结果。

在对象中使用时显示错误。

最佳答案

>>> a = 7 
>>> b = 2

如果你想要3.5,使用

>>> c = a / float(b)

如果你想要3,使用

>>> c = a / b

关于python - 在 swift 和 python 中从相同的返回类型获得不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45429455/

相关文章:

python - 在终端中执行带有多个参数的python函数

python - Gtk.EntryCompletion() 弹出状态以解决键绑定(bind)冲突

Python 正则表达式 : match a range of numbers with a separator

swift - 我的代码有什么问题?它说未解析的标识符

python - 从 AF 列及以后的 excel 中读取

python - 猴子修补@property

python - Django 查询集缓存与exists() 和values_list()

python - SQLite - 检查创建时的表格式并根据需要删除

ios - SpriteKit 暂停恢复错误

swift - 制作碰撞后不移动的节点 iOS 8